Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Problems in my class

This topic is 4471 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

Yep. This again. I had fixed this error in the past(or so I thought) but now it's back, and I can'r get it to compile.
//classes_CPP.cpp
#include "classes_H.h"

void Switch::Pull()
{
    if(Active != 1)
    {
        std::cout << OnSound << std::endl;
        Active = 1;
        std::cin.get();
    }
    else if(On_off == 1)
    {
        std::cout << OffSound << std::endl;
        Active = 0;
        std::cin.get();
    }
}

//classes_H.h
#ifndef classes_H
#define classes_H

class Switch
{
    public:
    Switch(std::string _OnSound_, std::string _OffSound_);
    Switch(std::string _OnSound_);
    ~Switch();
    
    bool On_off; //Can the switch be turned back off? 0 = no 1 = yes
    bool Active; //Whether the switch is on or off. 0 = off 1 = on
    std::string OnSound; //Words given to the player upon pulling the switch.
    std::string OffSound; //Words given the player upon turning off the switch
    
    void Pull();
};
#endif
Here are the errors: Compiler: Default compiler Building Makefile: "C:\My Documents\C++ Programs\My Programs\Text based Rpgs\Dark Cave\Makefile.win" Executing make... make.exe -f "C:\My Documents\C++ Programs\My Programs\Text based Rpgs\Dark Cave\Makefile.win" all g++.exe -D__DEBUG__ -S main_CPP.cpp -o nul -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include" -fexceptions -g3 In file included from functions_CPP.cpp:3, from main_CPP.cpp:2: classes_CPP.cpp:4: redefinition of `void Switch::Pull()' classes_CPP.cpp:4: `void Switch::Pull()' previously defined here classes_CPP.cpp:4: no `void Switch::Pull()' member function declared in class ` Switch' classes_CPP.cpp:5: confused by earlier errors, bailing out make.exe: *** [main_CPP.o] Error 1 Execution terminated Any and all help is apreciated. Thanks. -Servant

Share this post


Link to post
Share on other sites
Advertisement
Those error messages look suspiciously like you're including source files (.cpp files) in other source files. Don't do that.

Share this post


Link to post
Share on other sites
I now get many errors in the following files:
//classes_H.h
#ifndef classes_H
#define classes_H
#include <iostream>

typedef struct Item
{
std::string Name; //Name of the Item
std::string Sound; //Words given when item is used
int InRoom; //Room number inwhich this item is used
};

bool operator == (const Item & a, const Item & b)
{
return (a.Name == b.Name) && (a.Sound == b.Sound) && (a.InRoom == b.InRoom);
}

bool operator != (const Item & a, const Item & b)
{
return (a.Name != b.Name) && (a.Sound != b.Sound) && (a.InRoom != b.InRoom);
}


class Room
{
public:
Room(bool N, bool NE, bool E, bool SE, bool S, bool SW, bool W, bool NW, bool U, bool D);
Room();
~Room();

void Description(std::string line_one); //Description of the room given to player
void Description(std::string line_one, std::string line_two);
void Description(std::string line_one, std::string line_two, std::string line_three);
void Description(std::string line_one, std::string line_two, std::string line_three, std::string line_four);
void Description(std::string line_one, std::string line_two, std::string line_three, std::string line_four, std::string line_five);
//void Room::Description(std::string line_one, std::string line_two="", std::string line_three="", std::string line_four="", std::string line_five="");

void Sound();

void Set(std::string SetArea, Item SetRoomItem, int SetRoomNum);

int Number_of_lines;

std::string Line[5];

std::string Area; //The name of the area the room is in (example: 'Central cave')

Item RoomItem; //Holds what item is in the room

int RoomNum; //Holds the room's ID number

bool NORTH;
bool NORTHEAST;
bool EAST;
bool SOUTHEAST;
bool SOUTH; //Can you go south? 0 = NO 1 = YES
bool SOUTHWEST;
bool WEST;
bool NORTHWEST;
bool UP;
bool DOWN;
};

class Switch
{
public:
Switch(std::string _OnSound_, std::string _OffSound_);
Switch(std::string _OnSound_);
~Switch();

bool On_off; //Can the switch be turned back off? 0 = no 1 = yes
bool Active; //Whether the switch is on or off. 0 = off 1 = on
std::string OnSound; //Words given to the player upon pulling the switch.
std::string OffSound; //Words given the player upon turning off the switch

void Pull();
};

#endif



//classes_CPP.cpp
#include "classes_H.h"
////////////////////////////////////////SWITCH//////////////////////////////////
void Switch::Pull()
{
if(Active != 1)
{
std::cout << OnSound << std::endl;
Active = 1;
std::cin.get();
}
else if(On_off == 1)
{
std::cout << OffSound << std::endl;
Active = 0;
std::cin.get();
}
}

Switch::Switch(std::string _OnSound_)
{
OnSound = _OnSound_;
OffSound = "<Error: No Message>";
Active = 0;
On_off = 0;
}
Switch::Switch(std::string _OnSound_, std::string _OffSound_)
{
OnSound = _OnSound_;
OffSound = _OffSound_;
Active = 0;
On_off = 1;
}
Switch::~Switch(){ }
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////ROOM////////////////////////////////////////
Room::Room(bool N, bool NE, bool E, bool SE, bool S, bool SW, bool W, bool NW, bool U, bool D)
{
NORTH = N;
NORTHEAST = NE;
EAST = E;
SOUTHEAST = SE;
SOUTH = S;
SOUTHWEST = SW;
WEST = W;
NORTHWEST = NW;
UP = U;
DOWN = D;
}

Room::Room()
{
NORTH = 0;
NORTHEAST = 0;
EAST = 0;
SOUTHEAST = 0;
SOUTH = 0;
SOUTHWEST = 0;
WEST = 0;
NORTHWEST = 0;
UP = 0;
DOWN = 0;
Area = "";
RoomItem.InRoom = 0;
RoomItem.Name = "";
RoomItem.Sound = "";
RoomNum = 0;
Line[0] = "";
Line[1] = "";
Line[2] = "";
Line[3] = "";
Line[4] = "";
}

Room::~Room(){ }

void Room::Set(std::string SetArea, Item SetRoomItem, int SetRoomNum)
{
Area = SetArea;

RoomItem = SetRoomItem;

RoomNum = SetRoomNum;
}

void Room::Sound() //Gives the description of the room
{
int i = Number_of_lines;
bool stop = false;
while(!stop)
{
std::cout << Line << std::endl;
i--;
if(i = 0){stop = true;}
}
}

void Room::Description(std::string line_one) //Sets the description of the room
{
Line[0] = line_one;
Number_of_lines = 1;
}
void Room::Description(std::string line_one, std::string line_two)
{
Line[0] = line_one;
Line[1] = line_two;
Number_of_lines = 2;
}
void Room::Description(std::string line_one, std::string line_two, std::string line_three)
{
Line[0] = line_one;
Line[1] = line_two;
Line[2] = line_three;
Number_of_lines = 3;
}
void Room::Description(std::string line_one, std::string line_two, std::string line_three, std::string line_four)
{
Line[0] = line_one;
Line[1] = line_two;
Line[2] = line_three;
Line[3] = line_four;
Number_of_lines = 4;
}
void Room::Description(std::string line_one, std::string line_two, std::string line_three, std::string line_four, std::string line_five)
{
Line[0] = line_one;
Line[1] = line_two;
Line[2] = line_three;
Line[3] = line_four;
Line[4] = line_five;
Number_of_lines = 5;
}

/*void Room::Description(std::string line_one, std::string line_two="", std::string line_three="", std::string line_four="", std::string line_five="")
{
Number_of_lines = 0;
Line[0] = line_one;
Number_of_lines++;
if(!Line[1].empty())
{
Line[1] = line_two;
Number_of_lines++;
if(!Line[2].empty())
{
Line[2] = line_three;
Number_of_lines++;
if(!Line[3].empty())
{
Line[3] = line_four;
Number_of_lines++;
if(!Line[4].empty())
{
Line[4] = line_five;
Number_of_lines++;
} } } } }*/

////////////////////////////////////////////////////////////////////////////////




The errors are all basicly the same;
Multiple definition of 'x'
First defined here


How do I deal with these particular type of errors? Once I know how to get one, I should be able to get the rest.

Here is the entire error file:

Compiler: Default compiler
Building Makefile: "C:\My Documents\C++ Programs\My Programs\Text based Rpgs\Dark Cave\Makefile.win"
Executing make...
make.exe -f "C:\My Documents\C++ Programs\My Programs\Text based Rpgs\Dark Cave\Makefile.win" all
g++.exe -D__DEBUG__ main_CPP.o classes_CPP.o functions_CPP.o -o "Dark Cave.exe" -L"C:/Dev-Cpp/lib"

classes_CPP.o(.text+0x0): In function `ZSteqIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_ES8_':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp: multiple definition of `operator==(Item const&, Item const&)'
main_CPP.o(.text+0x0):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/main_CPP.cpp: first defined here
classes_CPP.o(.text+0x5a): In function `ZneRK4ItemS1_':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_H.h:18: multiple definition of `operator!=(Item const&, Item const&)'
main_CPP.o(.text+0x5a):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_H.h:18: first defined here
classes_CPP.o(.text+0xb4): In function `ZN6Switch4PullEv':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:4: multiple definition of `Switch::Pull()'
main_CPP.o(.text+0xb4):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:4: first defined here
classes_CPP.o(.text+0x162): In function `ZN6SwitchC2ESs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: multiple definition of `Switch::Switch(std::string)'
main_CPP.o(.text+0x162):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: first defined here
classes_CPP.o(.text+0x210): In function `ZN6SwitchC1ESs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: multiple definition of `Switch::Switch(std::string)'
main_CPP.o(.text+0x210):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: first defined here
classes_CPP.o(.text+0x2be): In function `ZN6SwitchC2ESsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: multiple definition of `Switch::Switch(std::string, std::string)'
main_CPP.o(.text+0x2be):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: first defined here
classes_CPP.o(.text+0x36a): In function `ZN6SwitchC1ESsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: multiple definition of `Switch::Switch(std::string, std::string)'
main_CPP.o(.text+0x36a):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: first defined here
classes_CPP.o(.text+0x416): In function `ZN6SwitchD2Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: multiple definition of `Switch::~Switch()'
main_CPP.o(.text+0x416):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: first defined here
classes_CPP.o(.text+0x442): In function `ZN6SwitchD1Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: multiple definition of `Switch::~Switch()'
main_CPP.o(.text+0x442):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: first defined here
classes_CPP.o(.text+0x46e): In function `ZN4RoomC2Ebbbbbbbbbb':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: multiple definition of `Room::Room(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'
main_CPP.o(.text+0x46e):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: first defined here
classes_CPP.o(.text+0x634): In function `ZN4RoomC1Ebbbbbbbbbb':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: multiple definition of `Room::Room(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'
main_CPP.o(.text+0x634):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: first defined here
classes_CPP.o(.text+0x7fc): In function `ZN4RoomC2Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: multiple definition of `Room::Room()'
main_CPP.o(.text+0x7fc):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: first defined here
classes_CPP.o(.text+0xa56): In function `ZN4RoomC1Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: multiple definition of `Room::Room()'
main_CPP.o(.text+0xa56):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: first defined here
classes_CPP.o(.text+0xcb0): In function `ZN4RoomD2Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: multiple definition of `Room::~Room()'
main_CPP.o(.text+0xcb0):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: first defined here
classes_CPP.o(.text+0xd0c): In function `ZN4RoomD1Ev':

C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: multiple definition of `Room::~Room()'
main_CPP.o(.text+0xd0c):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: first defined here
classes_CPP.o(.text+0xd68): In function `ZN4Room3SetESs4Itemi':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:78: multiple definition of `Room::Set(std::string, Item, int)'
main_CPP.o(.text+0xd68):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:78: first defined here
classes_CPP.o(.text+0xdaa): In function `ZN4Room5SoundEv':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:87: multiple definition of `Room::Sound()'
main_CPP.o(.text+0xdaa):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:87: first defined here
classes_CPP.o(.text+0xe02): In function `ZN4Room11DescriptionESs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:99: multiple definition of `Room::Description(std::string)'
main_CPP.o(.text+0xe02):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:99: first defined here
classes_CPP.o(.text+0xe2a): In function `ZN4Room11DescriptionESsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:104: multiple definition of `Room::Description(std::string, std::string)'
main_CPP.o(.text+0xe2a):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:104: first defined here
classes_CPP.o(.text+0xe6c): In function `ZN4Room11DescriptionESsSsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:110: multiple definition of `Room::Description(std::string, std::string, std::string)'
main_CPP.o(.text+0xe6c):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:110: first defined here
classes_CPP.o(.text+0xec4): In function `ZN4Room11DescriptionESsSsSsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:117: multiple definition of `Room::Description(std::string, std::string, std::string, std::string)'
main_CPP.o(.text+0xec4):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:117: first defined here
classes_CPP.o(.text+0xf36): In function `ZN4Room11DescriptionESsSsSsSsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:125: multiple definition of `Room::Description(std::string, std::string, std::string, std::string, std::string)'
main_CPP.o(.text+0xf36):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:125: first defined here
functions_CPP.o(.text+0x0): In function `ZNSt17_Rb_tree_iteratorISt4pairIKSsiERS2_PS2_EmmEv':
C:/Dev-Cpp/include/c++/bits/stl_tree.h: multiple definition of `operator==(Item const&, Item const&)'
main_CPP.o(.text+0x0):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/main_CPP.cpp: first defined here
functions_CPP.o(.text+0x5a): In function `ZneRK4ItemS1_':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_H.h:18: multiple definition of `operator!=(Item const&, Item const&)'
main_CPP.o(.text+0x5a):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_H.h:18: first defined here
functions_CPP.o(.text+0xb4): In function `ZN6Switch4PullEv':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:4: multiple definition of `Switch::Pull()'
main_CPP.o(.text+0xb4):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:4: first defined here
functions_CPP.o(.text+0x162): In function `ZN6SwitchC2ESs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: multiple definition of `Switch::Switch(std::string)'
main_CPP.o(.text+0x162):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: first defined here
functions_CPP.o(.text+0x210): In function `ZN6SwitchC1ESs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: multiple definition of `Switch::Switch(std::string)'
main_CPP.o(.text+0x210):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:20: first defined here
functions_CPP.o(.text+0x2be): In function `ZN6SwitchC2ESsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: multiple definition of `Switch::Switch(std::string, std::string)'
main_CPP.o(.text+0x2be):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: first defined here
functions_CPP.o(.text+0x36a): In function `ZN6SwitchC1ESsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: multiple definition of `Switch::Switch(std::string, std::string)'
main_CPP.o(.text+0x36a):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:27: first defined here

functions_CPP.o(.text+0x416): In function `ZN6SwitchD2Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: multiple definition of `Switch::~Switch()'
main_CPP.o(.text+0x416):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: first defined here
functions_CPP.o(.text+0x442): In function `ZN6SwitchD1Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: multiple definition of `Switch::~Switch()'
main_CPP.o(.text+0x442):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:33: first defined here
functions_CPP.o(.text+0x46e): In function `ZN4RoomC2Ebbbbbbbbbb':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: multiple definition of `Room::Room(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'
main_CPP.o(.text+0x46e):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: first defined here
functions_CPP.o(.text+0x634): In function `ZN4RoomC1Ebbbbbbbbbb':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: multiple definition of `Room::Room(bool, bool, bool, bool, bool, bool, bool, bool, bool, bool)'
main_CPP.o(.text+0x634):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:38: first defined here

functions_CPP.o(.text+0x7fc): In function `ZN4RoomC2Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: multiple definition of `Room::Room()'
main_CPP.o(.text+0x7fc):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: first defined here
functions_CPP.o(.text+0xa56): In function `ZN4RoomC1Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: multiple definition of `Room::Room()'
main_CPP.o(.text+0xa56):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:52: first defined here
functions_CPP.o(.text+0xcb0): In function `ZN4RoomD2Ev':

C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: multiple definition of `Room::~Room()'
main_CPP.o(.text+0xcb0):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: first defined here
functions_CPP.o(.text+0xd0c): In function `ZN4RoomD1Ev':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: multiple definition of `Room::~Room()'
main_CPP.o(.text+0xd0c):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:75: first defined here
functions_CPP.o(.text+0xd68): In function `ZN4Room3SetESs4Itemi':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:78: multiple definition of `Room::Set(std::string, Item, int)'

main_CPP.o(.text+0xd68):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:78: first defined here
functions_CPP.o(.text+0xdaa): In function `ZN4Room5SoundEv':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:87: multiple definition of `Room::Sound()'

main_CPP.o(.text+0xdaa):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:87: first defined here
functions_CPP.o(.text+0xe02): In function `ZN4Room11DescriptionESs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:99: multiple definition of `Room::Description(std::string)'
main_CPP.o(.text+0xe02):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:99: first defined here
functions_CPP.o(.text+0xe2a): In function `ZN4Room11DescriptionESsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:104: multiple definition of `Room::Description(std::string, std::string)'
main_CPP.o(.text+0xe2a):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:104: first defined here
functions_CPP.o(.text+0xe6c): In function `ZN4Room11DescriptionESsSsSs':

C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:110: multiple definition of `Room::Description(std::string, std::string, std::string)'
main_CPP.o(.text+0xe6c):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:110: first defined here
functions_CPP.o(.text+0xec4): In function `ZN4Room11DescriptionESsSsSsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:117: multiple definition of `Room::Description(std::string, std::string, std::string, std::string)'
main_CPP.o(.text+0xec4):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:117: first defined here
functions_CPP.o(.text+0xf36): In function `ZN4Room11DescriptionESsSsSsSsSs':
C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:125: multiple definition of `Room::Description(std::string, std::string, std::string, std::string, std::string)'
main_CPP.o(.text+0xf36):C:/My Documents/C++ Programs/My Programs/Text based Rpgs/Dark Cave/classes_CPP.cpp:125: first defined here

make.exe: *** ["Dark] Error 1

Execution terminated




Thanks for the help!

Share this post


Link to post
Share on other sites
When you define a function (provide the body) in a header it needs to be inline, either explicitly with the inline keyword or implicitly (such as when you define it inside the class definition).

Share this post


Link to post
Share on other sites
Now that it compiles, time to make it work (correctly), and make it right.

1) Your Item operator!= is just plain wrong. Hint: if the name matches, but the sound and inRoom don't, are the items equal?
Sometimes it's useful to be able to implement *all* of the relational operators, so that e.g. you can sort them. I like to do this by implementing a common 'cmp' (compare) function, which returns a value like what the C strcmp() does, and writing the operators in terms of the cmp result.

2) Your Room constructor taking 8 booleans is pretty brutal. Storing the booleans as 8 separate members is brutal too. Store an array, accept an array (copying in the values), and turn the names into enumeration values (then it would make sense to have them in uppercase; using uppercase for data members looks odd); you'll use them to index into the array.

3) Having a hard limit on the number of lines is not very nice. Especially since you have a static-sized array and then have to count the number of "used items" separately. Use a vector (or other container, but I will use vector) instead. It's also pretty ugly to have all those separate overloads for setting the description. It wouldn't be very nice to expect the client code to match up with your choice of storage container, but there's a simple way to handle this: accept an "iterator range" instead. That is, two arguments of some (templated) iterator type, which indicate the beginning and end of the sequence of lines to use.

4) Having the separate setting functions to initialize stuff after the constructor really isn't called for here - especially with the other changes above implemented first. You should aim to make your constructors be "complete".

5) Use initializer lists. Please.

6) This is C++, so don't use the "typedef struct idiom". Even for structs.

7) You should factor out that switch pausing logic into a separate function; you're likely to need it a lot, if this is the sort of project I think it is. Also, you don't have it quite right. :)

8) Don't implement destructors when they don't actually do anything.

9) Your headers should include the headers that are needed to make them compile
(and only those).

10) Make data members private where you can.

11) You should assign the values true and false to bools, rather than 0 and 1. You should not compare them to literal constants at all.

12) "Sound" is a weird name for the function that shows a text description of a room. Oh, and the way you implemented that function is really, really strange. Haven't you heard of a for loop?

13) Don't include the _H and _CPP in your *file names*. That's just redundant. The file extension already carries that information.


//classes.h
#ifndef classes_H
#define classes_H
#include <string>
#include <vector>

struct Item {
std::string Name; //Name of the Item
std::string Sound; //Words given when item is used
int InRoom; //Room number inwhich this item is used
};

inline int cmp(const Item& a, const Item& b) {
if (a.Name < b.Name) { return -1; }
if (a.Name > b.Name) { return 1; }
if (a.Sound < b.Sound) { return -1; }
if (a.Sound > b.Sound) { return 1; }
return a.InRoom - b.InRoom;
}

inline bool operator == (const Item & a, const Item & b) {
return cmp(a, b) == 0;
}

inline bool operator != (const Item & a, const Item & b) {
return cmp(a, b) != 0;
}

class Room {
std::vector<std::string> Text;
std::string Area; //The name of the area the room is in (example: 'Central cave')
Item RoomItem; //Holds what item is in the room
int RoomNum; //Holds the room's ID number
bool directions[8];

public:
enum { NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST, UP, DOWN } direction_t;

template <typename InputIterator>
Room(bool directions[8], InputIterator begin_line, InputIterator end_line,
const std::string& Area, const Item& RoomItem, int RoomNum) :
Area(Area), RoomItem(RoomItem), RoomNum(RoomNum);
Room();

void Show();
};

class Switch {
bool Resettable; // can the switch be turned back off if it is on?
bool Active; // is the switch on?
std::string OnSound; //Words given to the player upon pulling the switch.
std::string OffSound; //Words given the player upon turning off the switch

public:
Switch(std::string OnSound, std::string OffSound = "") : OnSound(OnSound), OffSound(OffSound), Resettable(OffSound != ""), Active(true) {}

void Pull();
};

//classes.cpp
#include <iostream>
#include <limits>
#include "classes.h"

void pause() {
// Throw away any as-yet unparsed input
std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
// Block until we get some input
std::cin.get();
// Throw that input away
std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
}

void Switch::Pull() {
if (!Active) {
Active = true;
std::cout << OnSound << std::endl;
pause();
} else if (Resettable) {
Active = false;
std::cout << OffSound << std::endl;
pause();
}
}

template <typename InputIterator>
Room(bool directions[8], InputIterator begin_line, InputIterator end_line,
const std::string& Area, const Item& RoomItem, int RoomNum) :
Area(Area), RoomItem(RoomItem), RoomNum(RoomNum) {
std::copy(directions, directions + 8, this->directions);
std::copy(begin_line, end_line, back_inserter(Text));
}

Room::Room() {
std::fill(directions, directions + 8, false);
}

void Room::Show() {
for (std::vector<std::string>::iterator it = Text.begin();
it != Text.end(); ++it) {
std::cout << *it << std::endl;
}
}

Share this post


Link to post
Share on other sites
Thanks...

I will implement some of the things you suggest, but some I will keep as it is. I am doing some of the things you have problems with intentionally, and some of the things that you changed are merely a matter of preference. For instance, all CAPS bool names, I did intentionally, and although you may dislike them, they help me immiedently recongize them in the way I use them. Also, both 'file.h' and 'file.cpp' show up as 'file' on my computer as I prefer extensions off. Only while programmer do I have a problem with them not being viewable, so I use 'file_H', 'file_CPP', and simular. Some people prefer to call the main file of the project the same as the project's name. I like to call it 'main'. But otherwise, besides my preferences, thanks for the advice. I will fix a few things you have pointed out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!