Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 分段错误。。ANSISTRINGTOINOCODESTRING作为第一个调试错误行。。末日等级制_C++_Oop_Virtual - Fatal编程技术网

C++ 分段错误。。ANSISTRINGTOINOCODESTRING作为第一个调试错误行。。末日等级制

C++ 分段错误。。ANSISTRINGTOINOCODESTRING作为第一个调试错误行。。末日等级制,c++,oop,virtual,C++,Oop,Virtual,我试图使这些类保持RAII标准(据我所知,我是一个业余程序员),但编译器/调试器抱怨缺少构造函数(括号为空),所以我添加了它们+set_value()函数 在一个简单的矩形上进行如此多的阐述,其目的是从我试图处理的前景问题中消除集成GUI类型(自上而下的类型,如按钮和文本字段)的模糊性:生活在左下坐标系统中的openGL 2D和3d图形 enum class eAnker:int{ high_left, high_right, low_left, low_righ

我试图使这些类保持RAII标准(据我所知,我是一个业余程序员),但编译器/调试器抱怨缺少构造函数(括号为空),所以我添加了它们+set_value()函数

在一个简单的矩形上进行如此多的阐述,其目的是从我试图处理的前景问题中消除集成GUI类型(自上而下的类型,如按钮和文本字段)的模糊性:生活在左下坐标系统中的openGL 2D和3d图形

enum class eAnker:int{
    high_left,
    high_right,
    low_left,
    low_right,
}

class anker
{
    friend node_handler;
    public:
        anker(){};
        anker(glm::dvec2 Vec2):pPoint( new glm::dvec2(Vec2) ){};
        anker(glm::dvec2 Vec2, eAnker ea):pPoint( new glm::dvec2(Vec2) ),anker_type(ea){};
        virtual ~anker(){ delete pPoint; };
        void set_value(glm::dvec2){pPoint=new glm::dvec2(v);}
        void set_anchor_type( eAnker ea){ anker_type=ea; }
        bool operator<( anker& a ){ return (pPoint->x<a.pPoint->x)<(pPoint->y<a.pPoint->y); };
    protected:
        glm::dvec2* pPoint;
        eAnker anker_type;
};


class nRect:public anker
{
    friend node_handler;
    public:
        nRect(){};
        nRect(glm::dvec2 p):anker(p){};
        nRect(glm::dvec2 p,double lineHeight, double letterWidth):anker(p),plHeight( new double(lineHeight)),       plWidth( new double(letterWidth) ){};
        virtual ~nRect(){
            delete plHeight;
            delete plWidth;
        };
        void set_dims( double Ww, double Lh ){
            plWidth= new double(Ww*LETTER_PIXEL_WIDTH);
            plHeight=new double(Lh*LINE_PIXEL_HEIGHT);
        }
    protected:
        double* plHeight;
        double* plWidth;
};


class node:public nRect
{
    friend node_handler;
    public:
    node(){};
    node(glm::dvec2 p):nRect(p){};
    node(glm::dvec2 p, double wW, double lH):nRect(p,wW,lH){};
    virtual ~node(){};
    void mouse_up(){
        on_click();
    };
    virtual void on_click(){
        /*
        bool b = !set_bit::is_closed(myBits);
        set_bit::as_closed(myBits,b);
        */
    };
protected:
    vector<node>::iterator iParent;
    bitset<32> myBits;
    string string_data;
    double my_ratio; 
    glm::dvec2 cursor_old;
};

class node_handler
{
    public:
        node_handler(){}
        ~node_handler(){};
        void set_root( glm::dvec2 anker, double pixel_width, double pixel_height ){
            if(!root_lock){
                node n(anker,pixel_width/25.0d,pixel_height/12.0d)  ;
                n.string_data="root";
                n.iParent = nodes.end();
                nodes.resize(10);
                nodes.at(0) = n ;
                current=nodes.begin();
                root_lock=true;
                node_counter++;
            }
            else{
                //cout << "BEEP nodes.root-error\n" << char(7);
            }
        }
        void split_current( double ratio, bool as_horizontal ){
            pair<node,node> res = split(current,ratio,as_horizontal);
            res.first.string_data="-closer";
            res.first.iParent=current;
            res.second.string_data="-farther";
            res.second.iParent=current;
            if(node_counter<int(nodes.size()) ) {
                nodes.at(node_counter)=res.first;
                current=nodes.begin()+node_counter;
                node_counter++;
                nodes.at(node_counter)=res.second;
                node_counter++;
            }
            else{
                cout << "no handler-space for more nodes\n" ;
            }
        //no errors so far. when leaving split_current(..), the execution halts with a SIGSEGV
}
    protected:
        int node_counter=0;
    private:
        pair<node,node>split( vector<node>::iterator& this_node, double ratio, bool as_horizontal ){
            this_node->my_ratio=ratio;
            double firstW, firstH;
            double secW, secH;
            glm::dvec2 afirst, asecond;
            if(as_horizontal ){
                // set values
            }
            return make_pair<node,node>( node(afirst ,firstW, firstH), node(asecond ,secW, secH) ) ;
        }
        vector<node>::iterator current;
        vector<node> nodes;
        bool root_lock{false};
};
/////////////////////

调试错误跟踪留下10行,没有一行指向代码中的特定行:
ntdll!RtlAnsiSringToUnicodeString()
??()
std::basic_Ostream是对同一代码的后续,可能包含对所描述的不稳定行为的正确答案。简言之(据我所知):具有指针成员的类需要定制的复制/赋值操作符,这些操作符在编写代码的背后工作,没有您的通知。。默认设置不起作用。

我没有提供它们。

请阅读一段独立的代码,我们可以复制和编译它,重现您遇到的问题。Richard。。我把这个问题完全重写了一遍。有很多代码,但你会发现其中大部分是锅炉板。可能没有帮助的是:你的原始成员被某些构造函数重载统一化了,所以如果(它们可能会)它们随后被读取,你会得到未定义的行为,任何事情都可能出错。确保原语成员始终初始化为确定值。使用类内成员初始化器设置常量默认值(以避免重复)。如果我们用空参数调用默认构造函数,那么:它们存在是因为编译器抱怨它们不存在。我不用它们。您可以遵循作为设置一部分的三个节点:根节点和它为其提供参数的两个拆分节点。给予第一、第一、第一价值观是“交易的秘密”。。。只需将根矩形分成两个矩形即可填充它。他们将成为控制按钮大小调整器的孩子。好的,明白了。。创建的节点是split(..)函数返回make_pair(节点(第一个、第一个w、第一个h)、节点(第二个、第二个secW、第二个secH))的本地节点;可以更改为返回make_对(节点*,节点*)。。。为什么每次我都感到惊讶?
node_handler nh;
    glm::dvec2 minor=glm::dvec2(0.0d, 0.0d);
    double width=800.0d;
    double height=600.0d;
nh.set_root(minor,width,height);
nh.split_current( 1.0d/10.0d , true );
//see nh.split_current() where SIGSEGV happens
The debug error-trace leaves 10 lines, noone pointing to a specific line in my code:

ntdll!RtlAnsiSringToUnicodeString()
??()
std::basic_Ostream<.....
std::clog()
std::clog()
??()
msvcat!_iob()
vtable for ct::anker
std::piecewise_construct