I have following code:
#include <string>
#include <vector>
class A {
public:
std::string s = "test";
};
class B {
public:
std::vector<A> vec;
};
int main()
{
std::vector<B> vec;
A a1 = A();
A a2 = A();
B b1 = B();
b1.vec.push_back(a1);
b1.vec.push_back(a2);
vec.push_back(b1); // push_1
vec.push_back(b1);
}
Whenever I execute this app under debugger, and execution procecss reachs instruction with comment push_1, the execution process is stopped, and I have two followings informations in my debugger output:
__lhs { s = "test" }
__rhs { s = "error reading variable: Cannot create a lazy string with address 0x0, and a non zero length.}
The application exit code is 0.
But when I remove property s of class A, or repleace with for instance int property, this strange behaviour does not occure. Why it is happening? Why the string occurrance in the class A, causes this error?
Well, your problem is one and half year old, but today I did have the same problem. The same code work fine when compile in a project and do not work when compile in other project. Like you, I was declaring and initializing a string variable in the class declaration. My solution was add a constructor and initialize the variable in the constructor and not in the class declaration. I know its sounds weird, many many years using c++, but from now on I will always initialize the string variables in the constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With