Take the 2-minute tour ×

I have been working in this program for a while but I am just not able to do it. It is for my programming class.

Here is the part of the program that I am (will have to) working on...

void AutoInventory::addCar()
if (count == list.length())
    list.changeSize(2* list.length());
cout <<"Enter the VIN: ";

cin >> VINnumber; // I get the same error when I try using the one in the public.
list[count] = c; // Error: identifier c is undefined
//list [next] = count;
cout << "Enter the make ";
cin >> make; // Error: identifier make is undefined
list[count] = c;
//list [next] = count;
cout<< "Enter the model ";
cin >> model;
list[count] = c;
//list [next] = count;
cout <<"Enter Year  ";
cin >> year;
list[count] = c;
//list [next] = count;
cout << "Car has been successfully added";


What I basically have to do is (in this function), prompt the user to enter the make, model, year of a car, and save the data on the "next element of the array" (which I'm not really sure what it means but I am not there yet, I still need to figure out the first part ) and print out the confirmation(which obviously doesn't have any errors ha ha!)

So, My question is, How do we use the variables that have been declared in another file and use it in this. To be specific, The Make, model, year is declared in a private section of another file (which I have #includeded in this file) however it gives me a compile error saying the identifiers make, model and yeear are undefined. the file that has these variables is ....


#include <string>
using namespace std;

class Automobile
void setVIN(string v);
void setMake(string ma);
void setModel(string mo);
void setYear(int y);
string getVIN();
string getMake();
string getModel();
int getYear();
string VINnumber;
string make;
string model;
int year;


If anyone could just let me know how to use the variable in the other file.

I am sorry If this question is against the rules of the website but I am desperate.

share|improve this question

1 Answer 1

To be specific, The Make, model, year is declared in a private section of another file ...

If the member variables of class are private, then they can be accessed only by its member functions ( Even if there is a inheritance relationship between the Automobile and AutoInventory). In your example, only Automobile class member functions can access them directly.

share|improve this answer
Yes, Im sorry. What I meant to say was, It is on the private, therefore I want to use the one in the public section. so for example, for string VINnumber in the private I want to use string v (from public) I tried doing it but it showed the same error (unidentified identifier) I hope this helps –  smiteNess May 7 '13 at 20:57
You need to have an object to access non-static data members of a class. –  Mahesh May 7 '13 at 21:02

Your Answer


