Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / string declaration in header file

Author
Message
Lord of the Games
18
Years of Service
User Offline
Joined: 27th May 2005
Location: Netherlands
Posted: 3rd Feb 2006 02:25 Edited at: 3rd Feb 2006 12:23
This is driving me crazy. I've made a header for my mainmenu wich contains a class. I've put a string in it and I'm trying to assign it in my constructor. The compiler swallows it, doesn't complain and runs the program, but the string stays empty. What am I doing wrong?

GlobalHeader contains <string> btw



I tried every combination of Name =.

DarkGameSDK
trying to understand DX...
Smithy
19
Years of Service
User Offline
Joined: 8th Dec 2004
Location: Switzerland
Posted: 3rd Feb 2006 08:43 Edited at: 3rd Feb 2006 08:48
Can you post the implementation of the constructor (or at least the part where you assign the string)?
(as I've done something similar a couple of times, IIRC, and it worked fine)

Hmm, you say you've tried other namings like m_Name?
Hmm...

Are you assigning like:


Or are you assinging like this:


//Awards: Best DM at NeverwinterConventionIII (NWCon3)
//Sys: Pentium IV 3200E/Prescott;800Mhz FSB;HT;WinXPPro;ATIR9700PRO;1024MB RAM(2x512MB"DualChanneled";VC++7.net;Delphi6;ADSL512;
Lord of the Games
18
Years of Service
User Offline
Joined: 27th May 2005
Location: Netherlands
Posted: 3rd Feb 2006 12:23 Edited at: 3rd Feb 2006 12:24
I tried both ways, but they won't work when i debug it keeps comming up with:

+ Name {???} std::basic_string<char,std::char_traits<char>,std::allocator<char> >
In the debug window.



DarkGameSDK
trying to understand DX...
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Feb 2006 13:07
Change your string definition in your class to:

std::string name;

Do not use 'using namespace' in a header to avoid doing this, as this will cause you problems further down the line.

For free Plug-ins and source code http://www.matrix1.demon.co.uk
Lord of the Games
18
Years of Service
User Offline
Joined: 27th May 2005
Location: Netherlands
Posted: 3rd Feb 2006 14:46 Edited at: 3rd Feb 2006 15:20
Wel I've changed it to std::string but it still doesn't.





BTW, my program locks up if I click the cross to close the window, any idea's?

DarkGameSDK
trying to understand DX...
Paisleys finest
18
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 3rd Feb 2006 16:38
How do you know for sure that the string is empty? Your syntax looks correct, for sure.

Add the following:

char *pszText = Name.c_str();

after stepping over that line pszText should be set to your string - I can't believe it would be anything else.

PS: O/T: As suggested before, probably better to use Hungarian notation, prefixing all member variables with m_

Current work in progress: Retro Remake of BRUCE LEE, by Datasoft (1984)
Lord of the Games
18
Years of Service
User Offline
Joined: 27th May 2005
Location: Netherlands
Posted: 3rd Feb 2006 17:26
Nope, can't get it to work. Name.cstr() returns a const char* btw. Well when I've got school again I'll complain there, they hopefully know what to do.

I still can't get the program to close properly with the close window button though.

DarkGameSDK
trying to understand DX...
Barnski
18
Years of Service
User Offline
Joined: 26th Jan 2006
Location: Switzerland, Zurich
Posted: 4th Feb 2006 17:03
You need to call LoopSDK() in your main loop (where you sync), if you dont want your window to freeze when clicking on the close button. In combination with that you should call dbDisableEscapeKey(), cause it would freeze then also if u hit escape key.
(u still can use it in ur code)

with the string problem I cant help you sorry..

greets,
barnski.

-- I just started with DarkSDK, by translating DBP Projects. --
Smithy
19
Years of Service
User Offline
Joined: 8th Dec 2004
Location: Switzerland
Posted: 6th Feb 2006 10:14
Lord of the Games
Quote: "Name.cstr() returns a const char* btw."


Btw, use this to make it "non-const":
const_cast< char*>( Name.cstr())


Hmm, very strange, since I am here on this DGDK forums,
none had a problem like this, I am sure it is one tiny, ugly bug that hides somewhere...
Hahaaa, wait until the Lord gets you hehehe

//Awards: Best DM at NeverwinterConventionIII (NWCon3)
//Sys: Pentium IV 3200E/Prescott;800Mhz FSB;HT;WinXPPro;ATIR9700PRO;1024MB RAM(2x512MB"DualChanneled";VC++7.net;Delphi6;ADSL512;
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Feb 2006 14:03
If it still doesn't work, then you are either *not* including the string header, or some other error is causing it to not be included.

For free Plug-ins and source code http://www.matrix1.demon.co.uk

Login to post a reply

Server time is: 2024-05-17 09:01:57
Your offset time is: 2024-05-17 09:01:57