I recently started teaching myself C++ from varrious tutorials and books, and once I felt I had a decent understanding of syntax, input, output and classes, I figured I'd try to write a basic text adventure console app.
The class definition seems to work fine, but I keep getting a "multiple definition" error on the testRoom instance I create, despite the fact that it's only created once.
At first I thought I might be calling the file twice (I'm keeping the list of rooms in a separate header file), but that is not the case. I've looked online and can't seem to figure out what is wrong with it...
source.cpp
roomDef.cppCode:/* Name: Text Adventure Copyright: None Author: Timothy Sassone Date: 14/02/09 22:42 Description: A basic text adventure engine, written to practice basic C++ skills. */ #include <iostream> #include <vector> //I plan on using a vector to hold the rooms #include <string> #include "roomDef.cpp" #include "roomListing.cpp" int main() { bool quit = 0; while(quit==0) { //Main loop quit=1; } return 0; }
roomListing.cppCode:#ifndef ROOM_DEF //Prevents repeated class definition #define ROOM_DEF #include <iostream> #include <string> using namespace std; class Room { private: string itsName; string itsDesc; public: string getName() { return itsName; } string getDesc() { return itsDesc; } void setName(string newName) { itsName=newName; } void setDesc(string newDesc) { itsDesc=newDesc; } Room(string name, string desc) { //constructor itsName=name; itsDesc=desc; } ~Room() {}; //Destructor }; #endif
I'm compiling with Dev-C++, and the error it gives is:Code:#ifndef ROOM_LIST //Prevents repeat definitions. #define ROOM_LIST #include "roomDef.cpp" //So I have access to the Room class Room testroom1("1", "2"); //Create two test rooms Room testroom2("2", "3"); #endif
multiple definition of `testroom1'
first is defined here
multiple definition of `testroom2'
first is defined here
ld returned 1 exit status
C:\Documents and Settings\Timothy Sassone\Text Adventure\Makefile.win [Build Error] ["Text] Error 1
Neither of the "first defined here" errors is giving me a line or even file name. Any idea why it is giving me this error?
Thank you for your time,
Timothy



LinkBack URL
About LinkBacks



