C++ Help Wanted

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
This header file was a .cpp and worked perfectly, but I am trying to convert it so I can use it as a class. THis is what I have so far and i have no idea how to fix most of these errors.

Here is the header file:
rpg.h

Here is the cpp:
rpg.cpp


Here are the error messages:

Compiling...
rpg.cpp
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(29) : error C2059: syntax error : 'constant'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(52) : error C2143: syntax error : missing ';' before ':'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(107) : error C2001: newline in constant
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(108) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(108) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(110) : error C2678: binary '<' : no operator defined which takes a left-hand operand of type 'class ostream_withassign' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(114) : error C2001: newline in constant
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(115) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(115) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(117) : error C2678: binary '<' : no operator defined which takes a left-hand operand of type 'class ostream_withassign' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(121) : error C2001: newline in constant
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(122) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(122) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(124) : error C2678: binary '<' : no operator defined which takes a left-hand operand of type 'class ostream_withassign' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(128) : error C2001: newline in constant
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(129) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(129) : error C2143: syntax error : missing ')' before '{'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(131) : error C2678: binary '<' : no operator defined which takes a left-hand operand of type 'class ostream_withassign' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\rpg\rpg.cpp(12) : error C2065: 'gameStart' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\rpg\rpg.cpp(13) : error C2065: 'gameLoop' : undeclared identifier
Error executing cl.exe.

rpg.exe - 20 error(s), 0 warning(s)


thanks for any help!
 

br0wn

Senior member
Jun 22, 2000
572
0
0
you have lots of syntax errors in rpg.h

some of the &quot;cout&quot; you use &quot;cout <&quot;, correct
one should be &quot;cout <<&quot;.

some line you ended with &quot;:&quot;, it should be end
with &quot;;&quot;

and in your rpg.cpp,

the two lines should be
myworld.gameStart();
myworld.gameLoop();
 

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
thanks. i fixed these. i also found errors where i used a &quot; instead of a '.

3 errors remaining:

c:\program files\microsoft visual studio\myprojects\rpg\rpg.h(29) : error C2059: syntax error : 'constant'
c:\program files\microsoft visual studio\myprojects\rpg\rpg.cpp(12) : error C2660: 'gameStart' : function does not take 0 parameters
c:\program files\microsoft visual studio\myprojects\rpg\rpg.cpp(13) : error C2660: 'gameLoop' : function does not take 0 parameters
 

br0wn

Senior member
Jun 22, 2000
572
0
0
you need to match those function calls (in class world, in rpg.h) with
the way you call it (in rpg.cpp).

In your rpg.h
gameStart has 2 arguments, thus you have to supply these 2 arguments
when you call gameStart from rpg.cpp

The same thing with gameLoop.


edit : either supply 2 arguments to your function call, or remove
the arguments from rpg.h.
Think which one actually you meant to create.
 

HigherGround

Golden Member
Jan 9, 2000
1,827
0
0
you also can't call costructors for data members in the header file

apmatrix<char>world(5,5);

should be apmatrix<char> world;

add a constructor for the World class

class World
{
public:
World( ) { world.resize(5, 5); }
.
.
.
};

 

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
When I add the parameters to the myWorld.gameStart and gameLoop, I get &quot;undefined identifier&quot; error. If I get rid of the parameters from the header file, I get all kinds of linking errors!
 

HigherGround

Golden Member
Jan 9, 2000
1,827
0
0
you have to declare the instances you want to pass...

.
.
.
myPosition location;
apmatrix<char> WorldMatrix;
char inputChar;

myWorld.gameStart(location, WorldMatrix);
myWorld.gameLoop(location, WorldMatrix, inputChar);
.
.
.


edit: damn typos :)
 

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
Compiling...
rpg.cpp
Linking...
rpg.obj : error LNK2001: unresolved external symbol &quot;public: __thiscall apstring::apstring(void)&quot; (??0apstring@@QAE@XZ)
rpg.obj : error LNK2001: unresolved external symbol &quot;public: __thiscall apstring::~apstring(void)&quot; (??1apstring@@QAE@XZ)
rpg.obj : error LNK2001: unresolved external symbol &quot;private: void __thiscall World::findExits(class apmatrix<char> &amp;,struct myPosition &amp;)&quot; (?findExits@World@@AAEXAAV?$apmatrix@D@@AAUmyPosition@@@Z)
rpg.obj : error LNK2001: unresolved external symbol &quot;class ostream &amp; __cdecl operator<<(class ostream &amp;,class apstring const &amp;)&quot; (??6@YAAAVostream@@AAV0@ABVapstring@@@Z)
rpg.obj : error LNK2001: unresolved external symbol &quot;class istream &amp; __cdecl getline(class istream &amp;,class apstring &amp;)&quot; (?getline@@YAAAVistream@@AAV1@AAVapstring@@@Z)
rpg.obj : error LNK2001: unresolved external symbol &quot;public: char const * __thiscall apstring::c_str(void)const &quot; (?c_str@apstring@@QBEPBDXZ)
rpg.obj : error LNK2001: unresolved external symbol &quot;public: class apstring const &amp; __thiscall apstring::eek:perator+=(class apstring const &amp;)&quot; (??Yapstring@@QAEABV0@ABV0@@Z)
rpg.obj : error LNK2001: unresolved external symbol &quot;public: __thiscall apstring::apstring(char const *)&quot; (??0apstring@@QAE@PBD@Z)
rpg.obj : error LNK2001: unresolved external symbol &quot;public: class apstring const &amp; __thiscall apstring::eek:perator=(char)&quot; (??4apstring@@QAEABV0@D@Z)
Debug/rpg.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.

rpg.exe - 10 error(s), 0 warning(s)


World myWorld;

apmatrix<char>world(5,5);
myPosition location;
char dir;

myWorld.gameStart(world, location);
myWorld.gameLoop(world, location, dir);
 

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
well thanks everyone I got it to run! But whether it is working right is another story. I'll go check that out now
 

HigherGround

Golden Member
Jan 9, 2000
1,827
0
0
N/M

Include apmatrix.cpp and apstring.cpp into the project (these are my best guesses as i never use the ap* classes). Project -> Add To Project -> Files (now find the source files, which should be in the VC Home/Include directory (where VC Home is the actual path to VC++)
 

Nessoldaccount

Senior member
Jun 4, 2000
483
0
0
ok another problem. In the dispPosition() function, where I have the infile:

while(getline(infile, var))
cout << endl << var;

It only displays the first line of the text file. What am I doing wrong?