Getting data through a class to a function.

This is a C++ problem and I'm using Juan Soulle's tutorials as a base.

I'm not sure if this is a beginner question but I count myself as a beginner having only done this for a few weeks.

My problem is,

I'm defining a class and using this line in main() to create the class...

cars another ("Fiesta", 30, 50, 90, 80);

I have found that for every car I will have to create a new car every time I want one within the program, this isn't my problem however. This another car however needs to be carried over to another function outside main.

1
2
3
4
deal()
{
cout << another.returnName(); 
}


Please note that returnName() was defined within the class of cars and it returns (or should return) Fiesta so it's a valid function. My main issue seems to be between the main() and deal()


Pass the car as a parameter to the function:

1
2
3
4
5
6
7
8
void deal( cars c ) {
    cout << c.returnName(); 
}

int main() {
    cars another( "fiesta", 30, 50, 90, 80 );
    deal( another );
}

Perfect.

Now I just have to get the returnName() working again.
Topic archived. No new replies allowed.