Mustang Evolution Forum banner

1 - 4 of 4 Posts

32 Posts
Discussion Starter #1
I am working on an array of classes so I can store some information that will be used later into my program. This is what I have for my array.

Car carArray[] = {Car ("Porsche", "911", "Silver", 2005, 50000),
Car ("Ford", "Mustang", "Red", 2007, 25000),
Car ("Voltzwagon", "Jetta", "Black", 2006, 16500)};

-- This is how I am calling it to check the information

cout << "Testing this array: " << carArray[0].getMake()
(had to split it up to make it show, or it would cut part of this line up.)
If I run it with just one of the .get, it will work. But once I add more than one, I get errors such as this.

'getModel' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'

left of '.getColor' must have class/struct/union type
left of '.getYear' must have class/struct/union type
left of '.getordervalue' must have class/struct/union type

38 Posts
Each of those method calls requires the carArray[ ] object instance. As shown, those after getMake do not have one.

cout << "Testing this array: " << carArray[0].getMake(),
carArray[0].getColor(), carArray[0].getYear(),

Hope that helps.

28 Posts
I'm not sure if the problem is as trivial as I imagined it, but did you try repeating the "carArray[0]" ?
like this:

cout << "Make: " << carArray[0].getMake();
cout << "Model: " << carArray[0].getModel();

if you want to combine them in one statement, do the following

cout << "Make:" << carArray[0].getMake() << " Model: " << carArray[0].getModel() << " Color:" << carArray[0].getColor();

This will NOT work:
you have to specify on which object to call the function, for every function.

Good luck!
1 - 4 of 4 Posts