使用指针和向量复制构造函数

我是这里的新用户,这是我的第一个问题,所以请不要轻易评价我。

The problem is to create copy constructor with pointers, also copy whole data in vector <stmt>* follow

它会编译,但随后会给出未处理的异常

我的第一次尝试是这样的:

struct stmt
{
    string lexeme;
    int *size;
    int *lay;
    bool *nl;
    vector<stmt>* follow;
    stmt(string l)
    {
        lexeme = l;
        size = new int;
        *size = l.size()+2;
        lay = new int;
        *lay = 0;
        nl = new bool;
        *nl = false;
        follow = new vector<stmt>;
    }
    stmt(const stmt &s)
    {
        lexeme = s.lexeme;      
        size = new int;         //Unhandled exception:std::length_error at memory location ...
        *size = *s.size;
        lay = new int;
        nl = new bool;
        follow = new vector<stmt>;
        follow = s.follow;
    }
};

我第二次也尝试这样做:

stmt(const stmt &s)
:lexeme.(s.lexeme), size (s.size), ......and so on
{}

不幸的是,这也无济于事。

我注意到当我尝试使用函数在向量中创建新元素时会发生这种情况。

例如:

stmt Function()
{
 // some Code
}

stmt MyStmt("Sth");
MyStmt.follow->emplace_back(Function()); //Maybe problem is here, but I don't know