Valgrind says invalid entry, but I just assign the line
I've been doing this for half a day, and I can't figure out why Valgrind is unhappy.
Valgrind whines:
==25658== Invalid write of size 4
==25658== at 0x40242F: MyObject::copy(MyObject const&) (MyObject.cpp:96)
==25658== by 0x402264: MyObject::operator=(MyObject const&) (MyObject.cpp:40)
MyObject.cpp: 96 is in my copy function
94 void MyObject::copy(const MyObject & other)
95 {
96 myVariable = other.myVariable;
MyObject.cpp: 40 is in the assignment statement
36 MyObject & MyObject::operator=(const MyObject & other)
37 {
38 if (this != &other)
39 {
40 copy(other);
41 }
42 return *this;
43 }
MyVariable is of type String
17 class MyObject
18 {
19 public:
20
21 /** My Variable */
22 string myVariable;
I see no reason why Valgrind would find a problem with this code. What am I missing?
+3
source to share