2013-05-07 16 views
0

我一直在這個程序中工作了一段時間,但我只是無法做到這一點。這是我的編程課。如何從其他文件添加標識符

這裏是我的方案的一部分(將要)工作...

void AutoInventory::addCar() 
{ 
if (count == list.length()) 
    list.changeSize(2* list.length()); 
count++; 
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; 
count++; 
cout << "Enter the make "; 
cin >> make; // Error: identifier make is undefined 
list[count] = c; 
//list [next] = count; 
count++; 
cout<< "Enter the model "; 
cin >> model; 
list[count] = c; 
//list [next] = count; 
count++; 
cout <<"Enter Year "; 
cin >> year; 
list[count] = c; 
//list [next] = count; 
count++; 
cout << "Car has been successfully added"; 

} 

我基本上需要做的是(在此函數),提示用戶輸入製作,模型,汽車年,並將數據保存在「陣列的下一個元素」(我不確定它是什麼意思,但我還沒有,但仍需要弄清楚第一部分)並打印出確認(這顯然沒有任何錯誤哈哈!)

所以,我的問題是,我們如何使用已在另一個文件中聲明的變量,並在此使用它。具體來說,Make,model,year是在另一個文件(我在此文件中包含#)的一個專用部分中聲明的,但它給了我一個編譯錯誤,說明make,model和yeear標識符是未定義的。 具有這些變量是文件....

#ifndef AUTOMOBILE_H 
#define AUTOMOBILE_H 

#include <string> 
using namespace std; 

class Automobile 
{ 
public: 
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(); 
private: 
string VINnumber; 
string make; 
string model; 
int year; 
}; 

#endif 

如果有人可以讓我知道如何使用變量中的其他文件。

對不起,如果這個問題是違反網站的規則,但我絕望。

回答

0

具體而言,廠名,型號,年份是在另一個文件上的私人地段宣佈...

如果類的成員變量是私人,那麼他們可以訪問只有通過其成員函數(即使在AutomobileAutoInventory之間存在繼承關係)。在您的示例中,只有Automobile類成員函數可以直接訪問它們。

+0

是的,很抱歉。 我的意思是說,它是私人的,所以我想用公共區域中的那個。所以例如,在私人字符串VINnumber我想使用字符串v(來自公衆) 我試過但它顯示相同的錯誤(未識別的標識符) 我希望這可以幫助 – smiteNess 2013-05-07 20:57:50

+0

您需要有一個對象來訪問非一個類的靜態數據成員。 – Mahesh 2013-05-07 21:02:06

相關問題