"..." was not declared in this scope??

Write your question here.
Hey. Im working on a text adventure game and Im not sure if the way Im doing it is the best. Basically in the beginning you can choose to be 2 sides, either evil or good and the story for both of them are different. so I have 2 classes. one for the story and the options you can pick in good, and one for the same reason in evil. And then in main I just have the switch case and stuff like that, but I got one problem for some odd reason. My switch case does not recognize a function that I wrote in my header file. You will first see my Main.cpp, then my header and then my class.pp. Thank you :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  #include "GoodSide.h"
#include <iostream>
#include <string>


using namespace std;



int main()
{

cout << "\tWelcome to my text adventure game\n" << endl;

cout << "Please enter your characters Name: ";
    string name;
    cin >> name;
    cout  << "\nWelcome " << name << endl;
    GoodSide GoodSideObject;
    GoodSideObject.SideChoice();

    int answer;

   do
    {
     cin >> answer;

     if (answer != 1 && answer != 2)
    cout << "That is not a valid Number.\n " << endl;

    }
           while (answer != 1 && answer != 2);

           switch(answer){
       case 1:
          PartOneStory();
        break;


           }



Header:

#ifndef GOODSIDE_H
#define GOODSIDE_H

#include <iostream>
using namespace std;

class GoodSide
{
    public:
        GoodSide();
        void SideChoice();
        void PartOneStory();




};

#endif

Class.cpp:

#include "GoodSide.h"
#include <iostream>

using namespace std;


GoodSide::GoodSide()
{
     cout << "\n\n*Use Numbers To Pick An Option* " << endl;
}

void GoodSide::SideChoice(){

cout << "\nPlease choose the side you would like to play in - ";
cout << "\n[1] The Good\n\n[2] The Evil" << endl;

}

void PartOneStory(){

cout << "You chose the good side. Let the game begin\n "  << endl;
cout << "You are located in a city named after the warrior who saved it from the evil\nmany years ago. The city of Redshore. " << endl;
cout << "You are no ordinary man in the City of Redshore. You are the king who rules it\nYou are seen as King of Justice, a good king.\nOne who only want what is best for his people" << endl;
cout << "but also a troubled man. You experienced something traumatizing when you\nwere a just a little boy, but no one knows about it,\nno one but yourself that is  " << endl;


}
PartOneStory() is a member function, not a global function. You need to have an instance of your class to call it from.

By the way, just a heads up: this design will not work very well. I would consider a design that uses polymorphism and which does not need a different function for each part of the story.
Last edited on
and line 86 should be
void GoodSide::PartOneStory(){
At line 36, you're trying to call a global function called PartOneStory(), not a method on an object.

At line 86, you define that global function.

But at line 57, you declare it as a method of GoodSide, not as a global function.
Last edited on
what do you mean by that? Sorry IM super new to all of this, would you mind demonstrating it?

Also is this a decent way of writing a text adventure game?
There have been replies and post edits - refresh the page.
they mean line 36 should probably be:
GoodSideObject.PartOneStory();
I know that this structure is not the best, but I started learning c++ less than a week ago, I dont think I can handle the polymorphism? I mean, isnt it okay for a beginner to do it like this and then when done take it to the next level?

Also thank you very much everyone who wrote, it worked <3
TarikNeaj wrote:
isnt it okay for a beginner to do it like this and then when done take it to the next level?
Yes, I was just warning you in advance ;)
Then I will take your warning to heart, and after Im done with this one use polymorphism or whatever :D thank you very much <33

(just a question, is it okay if I like add you on skype or something, just incase Something goes horrible wrong? I would love to be able to have someone to ask, would help alot)
Topic archived. No new replies allowed.