#### Archived

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

# Problem with my fileclass

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

## 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 on other sites
Your allocation line is wrong, it should look like this:

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 on other sites
but when u declare one the kompiletime way

cFilehandle hej("hej.hej");

##### Share on other sites
quote:
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''