stringw problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kwitee
Posts: 8
Joined: Fri May 07, 2010 9:16 pm

stringw problem

Post 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?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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?
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

:shock:
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
kwitee
Posts: 8
Joined: Fri May 07, 2010 9:16 pm

Post 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"); 
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Can't do much without seeing the rest of the code. It would help us if you posted the class.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

Wait, is that code from the constructor? Infinite recursion FTW
kwitee
Posts: 8
Joined: Fri May 07, 2010 9:16 pm

Post 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.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post 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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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).
Post Reply