Compile errors

Mar 11, 2020 at 1:53pm
Hello everyone, I have the source code for this program I'm trying to compile but I'm receiving many errors at this point idk where to start except the first error (knowledge from a guide) ive tried deleting the lines of code that contains the errors but that only seems to lead to more problems. Does anyone have any advice for a beginner? Should I fix the lines of code or delete them? I use cmd gcc compiler, codeblocks, visual studio build tools and visual studio

If you have any advice or willing to help me with this it would be greatly appreciated thanks
Last edited on Mar 11, 2020 at 1:54pm
Mar 11, 2020 at 2:05pm
Hello itachix,

First it is very helpful if you post the offending code so everyone can see what you have.

When posting code and do not take this wrong its just a copy and paste:


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.


If your program uses an input file provide the file or a fair sample to work with. It is better that everyone can use the same input information.

When referring to errors post the whole error message, those here get more from the message than you do right now and can help to explain the error message.

Usually it is best to start with the first error message and fix that, recompile and see what is left. Sometimes fixing one error can eliminate several.

Andy
Mar 11, 2020 at 2:20pm
Thanks for the fast reply Andy. So here is what I am working with, I have a folder that contains mutiple .cpp and .hpp files. I'm not sure how to use code tags at the moment but I will look into it and post the code here in a few when I get on my laptop. But anyways since they are multiple .cpp files and .hpp files. The first error message I'm getting is stdafx.h: no such file or directory.. which in the first .cpp I'm trying to compile
Last edited on Mar 11, 2020 at 2:20pm
Mar 11, 2020 at 2:21pm
#include "character.hpp"

void Character::Copy(Character &character)
{
name = character.name;
id = character.id;
map = character.map;
x = character.x;
y = character.y;
direction = character.direction;
level = character.level;
gender = character.gender;
race = character.race;
maxhp = character.maxhp;
hp = character.hp;
maxtp = character.maxtp;
tp = character.tp;
for(int i = 0; i < 9; ++i) { paperdoll[i] = character.paperdoll[i]; }
sitting = character.sitting;
hidden = character.hidden;
}

void Character::AddItem(short id, int amount)
{
for(unsigned int i = 0; i < inventory.size(); ++i)
{
if(inventory[i].id == id)
{
inventory[i].amount += amount;
return;
}
}

Character_Item item(id, amount);
inventory.push_back(item);
}

void Character::DelItem(short id, int amount)
{
int place = -1;
for(unsigned int i = 0; i < inventory.size(); ++i)
{
if(inventory[i].id == id)
{
place = i;
break;
}
}

if(place != -1)
{
if(--inventory[place].amount == 0) inventory.erase(inventory.begin() + place);
}
}

int Character::HasItem(short id)
{
for(unsigned int i = 0; i < inventory.size(); ++i)
{
if(inventory[i].id == id)
{
return inventory[i].amount;
}
}

return 0;
}
Mar 11, 2020 at 2:24pm


C:\Users\SESC>cd desktop

C:\Users\SESC\Desktop>cd test

C:\Users\SESC\Desktop\Test>gcc character.cpp
In file included from character.cpp:1:0:
character.hpp:4:20: fatal error: stdafx.h: No such file or directory
#include "stdafx.h"
^
compilation terminated.

C:\Users\SESC\Desktop\Test>

which is the error should I just delete
#include "stdafx.h" in the character.hpp or do I need to fix this error
Last edited on Mar 11, 2020 at 2:26pm
Mar 11, 2020 at 2:48pm
Update : I deleted the stdafx.h and it worked but now I'm getting more errors, what should I do? these are the errors I'm getting



eoclient.cpp:199:76: error: expected primary-expression before '>' token
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)
^
eoclient.cpp:199:77: error: '::iterator' has not been declared
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)
^~
eoclient.cpp:199:77: note: suggested alternatives:
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algoba
se.h:65:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\list:60,
from socket.hpp:15,
from eoclient.hpp:8,
from eoclient.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_iterator_base_types.h:118:12
: note: 'std::iterator'
struct iterator
^~~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_iterator_base_types.h:118:12
: note: 'std::iterator'
eoclient.cpp:199:111: error: 'it' was not declared in this scope
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)

^~
eoclient.cpp:199:117: error: 'handlers' was not declared in this scope
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)

^~~~~~~~
eoclient.cpp: At global scope:
eoclient.cpp:255:1: error: 'InitReply' does not name a type
InitReply EOClient::Init(int hdid, int version)
^~~~~~~~~
eoclient.cpp: In member function 'bool EOClient::CreateAccount(std::__cxx11::str
ing, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, std::__cx
x11::string, std::__cxx11::string)':
eoclient.cpp:316:5: error: 'auto_ptr' is not a member of 'std'
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^~~
eoclient.cpp:316:37: error: expected primary-expression before '>' token
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^
eoclient.cpp:316:39: error: 'reader' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^~~~~~
eoclient.cpp:316:84: error: 'WaitFor' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);

^
eoclient.cpp:326:5: error: 'util' has not been declared
util::sleep(3.0);
^~~~
eoclient.cpp:339:27: error: 'util' has not been declared
packet.AddBreakString(util::to_string(hdId));
^~~~
eoclient.cpp: At global scope:
eoclient.cpp:355:50: error: 'Gender' has not been declared
bool EOClient::CreateCharacter(std::string name, Gender gender, Skin skin, shor
t hairStyle, short hairColor)
^~~~~~
eoclient.cpp:355:65: error: 'Skin' has not been declared
bool EOClient::CreateCharacter(std::string name, Gender gender, Skin skin, shor
t hairStyle, short hairColor)
^~~~
eoclient.cpp: In member function 'bool EOClient::CreateCharacter(std::__cxx11::s
tring, int, int, short int, short int)':
eoclient.cpp:357:5: error: 'util' has not been declared
util::sleep(3.0);
^~~~
eoclient.cpp:362:5: error: 'auto_ptr' is not a member of 'std'
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^~~
eoclient.cpp:362:37: error: expected primary-expression before '>' token
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^
eoclient.cpp:362:39: error: 'reader' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^~~~~~
eoclient.cpp:362:85: error: 'WaitFor' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);

^
eoclient.cpp:386:18: error: 'CHARACTER_OK' was not declared in this scope
if(result != CHARACTER_OK) return false;
^~~~~~~~~~~~
eoclient.cpp:402:19: error: 'class Character' has no member named 'admin'
character.admin = static_cast<AdminLevel>(reader->GetChar());
^~~~~
eoclient.cpp:402:39: error: 'AdminLevel' does not name a type
character.admin = static_cast<AdminLevel>(reader->GetChar());
^~~~~~~~~~
eoclient.cpp:411:9: error: 'myCharacters' was not declared in this scope
myCharacters[id] = character;
^~~~~~~~~~~~
eoclient.cpp: In member function 'bool EOClient::RemoveCharacter(std::__cxx11::s
tring)':
eoclient.cpp:422:7: error: 'map' is not a member of 'std'
for (std::map<int, Character>::iterator it = myCharacters.begin(); it != myCha
racters.end(); ++it)
^~~
eoclient.cpp:422:16: error: expected primary-expression before 'int'
for (std::map<int, Character>::iterator it = myCharacters.begin(); it != myCha
racters.end(); ++it)
^~~
eoclient.cpp:422:69: error: 'it' was not declared in this scope
for (std::map<int, Character>::iterator it = myCharacters.begin(); it != myCha

Last edited on Mar 11, 2020 at 2:53pm
Mar 11, 2020 at 4:18pm
Hello itachix,

Just so you know this will take me a little while to get into my IDE and tested.

The "stdafx.h" file is a VS 2015 file for precompiled headers. If you use it you need to learn not to. If you are not use to it VS stands for Visual Studio.

When it comes to using code tags read the second link I provided. I have found it explains better.

Andy
Mar 11, 2020 at 8:46pm
Hey Andy let me know once you've tested it in your IDE
Topic archived. No new replies allowed.