Problem with my fileclass
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.
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.
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.
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''
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement