Runtime error. Terminate called after throwing an instance of std::length_error

Mar 26, 2019 at 3:19pm
I get a Runtime error which i can't understand. Please help!

class A
{ private:
string x, string y;
double z;
public:
A(string,string,double) // parameterized constructor
}

A CreateA(A& newA) // function returning an A object
{
newA = A(a,b,c) // a,b,c are entered by user from cin as string,string,
// double respectively.
}

int main()
{
A a;
vector <A> list;
list.push_back(CreateA(a));
}






Mar 26, 2019 at 3:25pm
you did not return anything from CreateA which is misnamed badly. (It does not create anything).

You need to return newA in (and, it should be A& CreateA(... ) I believe)
see if that works?
Mar 26, 2019 at 3:48pm
Thank you Jonnin. I made the function CreateA() as a void function and it worked. There was no need for me to return any thing because i passed by reference. Thanks again!
Topic archived. No new replies allowed.