How do I create an object inside another class?

Hey, I have only been programming for a couple of days and Im trying to do a
text adventure game, the format Im using is awful but I think it will have to do
for a first timer, Im thinking of making a couple of these with improvments each time. Here is the problem. I currently have 2 classes. One for the story, and one for the options given to the player and the switch statements are in my main.cpp. But It gets really messy and I want to have the switch statements in my options class aswell, or in a new class entirely doesnt matter, the problem is that. When I try and for example create an object from my story class, and then call for a certain story it says its not declared. I cant create or call a function from the story class to the options class. Am I explaining myself good enough? I'll put some code down below. The first one is a function inside my story class. The second one is the switch function inside my option class that cant declare a function from the story class.


1
2
3
4
5
6
7
8
9
10
11
12
13

void GoodSideStory::SP3FC(){

}

int answer;
cin >> answer;

switch (answer){

case 1:
        GoodSideStoryObject.SP3FC();
        GoodSideOptionsObject.DYCT();
        GoodSideOptionsObject.OP3();
                                    break;

Last edited on
I'm no expert, but I would create an instance of GoodSideStory with global scope and then you can reach into its function calls (as long as they are public!) in your options class.
That is exactly what I have been looking for, but I couldnt find any information of it, would you happen to have any?
Topic archived. No new replies allowed.