hello ive been working with c++ for a few weeks now and from yesterday ive attempting to write a console game but i keep getting an error.

//where all the noise is coming from

class Story{

public:
    Story();
    ~Story();
    void mainMenu();
    void start();

private:
    void levelOne();
    void judgement();
};


Story::Story(){

}

Story::~Story(){

}

//error console

obj\Debug\E\Project3\Project3\GameLoop.o||In function `Story':|
E:\Project3\Project3\story.h|16|multiple definition of `Story::Story()'|
obj\Debug\E\Project3\Project3\story.o:E:\Project3\Project3\story.h|16|first defined here|
obj\Debug\E\Project3\Project3\GameLoop.o||In function `~Story':|
E:\Project3\Project3\story.h|20|multiple definition of `Story::~Story()'|
obj\Debug\E\Project3\Project3\story.o:E:\Project3\Project3\story.h|20|first defined here|
obj\Debug\E\Project3\Project3\GameLoop.o||In function `Story':|
E:\Project3\Project3\story.h|16|multiple definition of `Story::Story()'|
obj\Debug\E\Project3\Project3\story.o:E:\Project3\Project3\story.h|16|first defined here|
obj\Debug\E\Project3\Project3\GameLoop.o||In function `~Story':|
E:\Project3\Project3\story.h|20|multiple definition of `Story::~Story()'|
obj\Debug\E\Project3\Project3\story.o:E:\Project3\Project3\story.h|20|first defined here|
||=== Build finished: 8 errors, 0 warnings ===|

With the exceptions of inline functions and templates, you do not want to have function implementations inside of a header file. You generally need to separate then out of the header and into a code file that will be compiled. Also, you want to use #include guards around the header files themselves, to prevent multiple inclusions in the same compilation unit. This should give you two files that look like this:

story.h

#ifndef STORY_H
$define STORY_H

class Story{

public:
    Story();
    ~Story();
    void mainMenu();
    void start();

private:
    void levelOne();
    void judgement();
};

#endif

and

story.cpp

#include "story.h"



Story::Story(){

}

Story::~Story(){

}

thanks for the quick reply. i tried your example and i did not get back the same errors only

E:\Project3\Project3\story.h|2|error: '$define' does not name a type|
E:\Project3\Project3\story.cpp|8|error: 'Story' does not name a type|
E:\Project3\Project3\story.cpp|12|error: 'Story' does not name a type|
E:\Project3\Project3\story.cpp|16|error: 'Story' has not been declared|
E:\Project3\Project3\story.cpp|21|error: 'Story' has not been declared|
E:\Project3\Project3\story.cpp|27|error: 'Story' has not been declared|
E:\Project3\Project3\story.cpp|32|error: 'Story' has not been declared|
||=== Build finished: 7 errors, 0 warnings ===|

OK, my bad on that; it should have read #define, not $define. I apologize for the mistake.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.