S
Sowen
Hi,
I have an object "elem", there are only simple functions inside, like
setName, getName, and three constructors
Now I have another class "Base", need an array of elem to initialize
class Base
{
public:
Base( elem **elements, int count );
protected:
elem **_elements;
}
I don't want to use outside pointer, which means I don't want _elements =
elements, actually, it works well except the problem of security
Therefore, in the Base constructor, I want to allocate a new space for the
array
Base::Base(elem **elements, int count)
{
// _elements = elements; // do not use this
_elements = new elem[count];
for (int i=0; i< count; i++)
{
assert(elements!=NULL);
_elements = new elem(elements->getName());
cout << elements->getName() << endl;
}
}
But, a strange problem is here, there are some elements lose "Name" !
What I mean is when I print elements->getName(), which returns a char,
some of them are missed, become empty
even I move this line before "assert"
If I just set _elements = elements, and then print, nothing will be missed
Now I am really clueless, anyone has an idea?
Thank you very much!
--
Best Regards!
Sowen Cheung
http://com.angGoGo.com
http://www.angGoGo.com
http://biz.angGoGo.com
I have an object "elem", there are only simple functions inside, like
setName, getName, and three constructors
Now I have another class "Base", need an array of elem to initialize
class Base
{
public:
Base( elem **elements, int count );
protected:
elem **_elements;
}
I don't want to use outside pointer, which means I don't want _elements =
elements, actually, it works well except the problem of security
Therefore, in the Base constructor, I want to allocate a new space for the
array
Base::Base(elem **elements, int count)
{
// _elements = elements; // do not use this
_elements = new elem[count];
for (int i=0; i< count; i++)
{
assert(elements!=NULL);
_elements = new elem(elements->getName());
cout << elements->getName() << endl;
}
}
But, a strange problem is here, there are some elements lose "Name" !
What I mean is when I print elements->getName(), which returns a char,
some of them are missed, become empty
even I move this line before "assert"
If I just set _elements = elements, and then print, nothing will be missed
Now I am really clueless, anyone has an idea?
Thank you very much!
--
Best Regards!
Sowen Cheung
http://com.angGoGo.com
http://www.angGoGo.com
http://biz.angGoGo.com