Page 1 of 1

stringw problem

Posted: Mon Apr 18, 2011 2:43 pm
by kwitee
I know this is more like C++ problem, but I am using irrlicht data types, so I am posting this here in case there were some known bugs.

My class has constructor with stringw as an argument. At first I create pointer to my class, and then I use my constructor to allocate the data to my pointer.

Code: Select all

class_node * test;
test = &class_node(L"test string");
All my data from the class is still valid, but string is defective. I thing the copy constructor is not called in this case. How can I fix this?

Posted: Mon Apr 18, 2011 3:42 pm
by hybrid
Completely broken, weird, buggy, worse than nightmare code. Just restart your C++ tutorials and ask again later.
BTW: You rocmpiler should warn you about dangerous fragments in your code. What about turning on warning, or read those warnings?

Posted: Mon Apr 18, 2011 4:15 pm
by ChaiRuiPeng
:shock:

Posted: Mon Apr 18, 2011 4:40 pm
by kwitee
hybrid wrote:Completely broken, weird, buggy, worse than nightmare code.
I admit that this is not OK, I am still learning. These 2 lines are only an example of what am I trying to do.
You rocmpiler should warn you about dangerous fragments in your code. What about turning on warning, or read those warnings?
My compiler (VS2010) did not warn me about this.

This is my second try:

Code: Select all

class_node * test; 
.
.
test = new class_node(L"test string"); 

Posted: Mon Apr 18, 2011 5:20 pm
by Radikalizm
ChaiRuiPeng wrote::shock:
QFT

Posted: Mon Apr 18, 2011 5:25 pm
by Lonesome Ducky
Can't do much without seeing the rest of the code. It would help us if you posted the class.

Posted: Mon Apr 18, 2011 6:04 pm
by hendu
Wait, is that code from the constructor? Infinite recursion FTW

Posted: Mon Apr 18, 2011 7:50 pm
by kwitee
Lonesome Ducky wrote:Can't do much without seeing the rest of the code. It would help us if you posted the class.
The string is now working properly. I see now that I must work on my C++ basics :oops:
hendu wrote: Wait, is that code from the constructor? Infinite recursion FTW
No, it isn't.

Posted: Mon Apr 18, 2011 7:55 pm
by Radikalizm
hendu wrote:Wait, is that code from the constructor? Infinite recursion FTW
That would've probably caused a stack overflow, so he would have noticed that :D

Posted: Mon Apr 18, 2011 7:56 pm
by hybrid
At least if the text in the first posting was correct, it's not from the constructor. But extrapolating from the early attempts, I guess that the constructor uses an assignment from pointer to char array or something like that. So yeah, no further help possible, show the full code instead.
BTW: Yeah, this way to use the constructor is better. But make sure you clean up all the nodes. Otherwise, you could maybe use statically allocated objects (no new and pointer things, automatic memory cleanup, but limited lifetime).