Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Leadorn

Problem with my fileclass

This topic is 5784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi This is a new problem for me, ive created a class for reading and writing to my file. And a use new to allocate a new Filehandleclass. cFilehadle *Filehandle = new cFilehandle; this works. but I want to add filename input to the construktor. construktor cFilehandle(char *szFilename); allocation cFilehadle *Filehandle("File.hej") = new cFilehandle; i get some weard problem. First is there any problem with my allocation. vc++ error. --------------------Configuration: GameServer - Win32 Debug-------------------- Compiling... Main.cpp error C2059: syntax error : ''string'' error C2059: syntax error : ''string'' error C2072: ''Filehandle'' : initialization of a function error C2512: ''cFilehandle'' : no appropriate default constructor available error C2227: left of ''->PrintPlayers'' must point to class/struct/union error C2541: delete : cannot delete objects that are not pointers cCommunication.cpp error C2059: syntax error : ''string'' error C2227: left of ''->ReadPlayerData'' must point to class/struct/union cFilehandle.cpp error C2059: syntax error : ''string''cServer.cpp error C2059: syntax error : ''string''ServerConsole.cpp error C2059: syntax error : ''string'' error C2227: left of ''->FindPlayer'' must point to class/struct/union error C2227: left of ''->WritePlayerData'' must point to class/struct/union error C2227: left of ''->CreateNewDataFile'' must point to class/struct/union It seems that there are only errors when i use new to allocate memory.

Share this post


Link to post
Share on other sites
Advertisement
Your allocation line is wrong, it should look like this:
cFilehadle *Filehandle = new cFilehandle("File.hej");

Try that and see what errors you get. Syntax error "string" leads me to believe you forgot to #include <string> or "use namespace std;". Try std::string and see if that works.

Share this post


Link to post
Share on other sites
quote:
Original post by Leadorn
but when u declare one the kompiletime way
cFilehandle hej("hej.hej");

That would create the object on the stack. The new operator will create the object on the heap.

cFilehandle hej("hej.hej");
is the same as
cFilehandle hej = cFilehandle("hej.hej");



Update GameDev.net system time campaign: ''date ddmmHHMMYYYY''

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!