Ron Natalie wrote:
we*****@yahoo.com wrote: My bad, made a mistake, here is my correct question to be asked:
I have a class, and string members are initilized through their own
ctors:
class my_class{
public:
my_class();
~my_class();
private:
string myData1;
string myData2;
};
my_class::my_class() myData1(), myData2()
This is ill-formed syntax (you need a :) and totally redundant.
The two strings will be default initiallized (it's only POD's
that the stupid-assed language doesn't bother to properly
default initialize without being told) without it.
Do we have a way
to force allocator being called or is there other explanation on this?
How could this happen?
Most likely you are screwing up something somewhere else and it's
just showing up here.
Common errors are passing (char*) NULL to one of the string member
functions or otherwise writing off some piece of dyanamic storage.
Post a complete, minimal program that demosntrates the problem.
Here is similar class we used and it generates core-dump for one of two
builts.
class my_class{
public:
my_class();
~my_class();
void setData1(const string input) { myData1 = input; }
:
:
private:
string myData1;
string myData2;
};
my_class::my_class() : myData1(), myData2()
{
}
When member function setData1() is called, it sometimes core-dump(in
one built) at memmove. Here is the stack trace(all names are replaced
with dummy ones):
Stack Trace for p1.1, Program mytest
*[0] memmove(0x1, 0x10ac2551, 0x3) [0xbffa0d66]
[1] basic_string<T1, T2, T3>::append<U1>(U1, U1, forward_iterator_tag)
[with T1=char, T2=char_traits<char>, T3=allocator<char>, U1=const char
*, return type=basic_string<char, char_traits<char>, allocator<char>>
&](this=0xed0b308, __first="5354", __last="",
={}) [mytest.C@stl_uninitialized.h@85]
[2] basic_string<T1, T2, T3>::_M_append_dispatch<U1>(U1, U1,
__false_type) [with T1=char, T2=char_traits<char>, T3=allocator<char>,
U1=const char *, return type=basic_string<char, char_traits<char>,
allocator<char>> &](this=0xed0b308, __f="5354", __l="",
={}) [mytest.C@string@607]
[3] basic_string<T1, T2, T3>::append<U1>(U1, U1) [with T1=char,
T2=char_traits<char>, T3=allocator<char>, U1=const char *, return
type=basic_string<char, char_traits<char>, allocator<char>>
&](this=0xed0b308, __first="5354", __last="") [mytest.C@string@564]
[4] basic_string<T1, T2, T3>::assign(const T1 *, const T1 *) [with
T1=char, T2=char_traits<char>, T3=allocator<char>, return
type=basic_string<T1, T2, T3> &](this=0xed0b308, __f="5354",
__l="") [mytest.C@string@1302]
[5] my_class::setData1 (basic_string<char, char_traits<char>,
allocator<char>>)(this=0xed0ae68, input={"5354", "",
"e"}) [mytest.C@string@360]
I did some tests e.g., by adding myData1.reverse(10) in ctor, still it
core-dumps. You see that the arg passed to setData1() has meaningful
value, I don't think that there is the bug in code, but may have
something to do with compiler(maybe?). I need advice howto approach
this. Thx