2012-02-05 12 views
0

devices.hファイルアーキテクチャx86_64の未定義シンボル。私のコードに何が問題なの?

#ifndef DEVICES_H 
#define DEVICES_H 

class malfunctionRecord 
{ 
private: 
int Num_Malfunction_Detection; 
int Type_Malfunction; 
int Last_Malfunction; 

public: 
    malfunctionRecord(); 
    void malfunction(int mlfn,int tm); 
    void display(); 
    int getRecord(int*m,int*t); 

}; 

class device 
{ 
private: 
    char *Name; 
    malfunctionRecord malfunctionRec; 
    int Serial_Num; 
    int Value_Device; 

public: 
    device(char*n,int sn); 
    ~device(); 
    void display(); 
    void recordMalfunction(int m,int t); 
    int getMalfunctionRecord(int *m,int *t); 
    int amIThisDevice(char*n); 

}; 

#endif 

(これは私のdevices.cppファイルです)

#include<iostream> 
#include "devices.h" 
using namespace std; 

malfunctionRecord::malfunctionRecord() 
{ 
    Num_Malfunction_Detection=0; 
    Last_Malfunction=0; 
    Type_Malfunction=='No_Malfunction'; 
} 

void malfunctionRecord::malfunction(int mlfn,int tm) 
{ 
    Num_Malfunction_Detection=Num_Malfunction_Detection+mlfn; 
    Last_Malfunction=Last_Malfunction+tm; 
} 

void malfunctionRecord::display() 
{ 
    if (Num_Malfunction_Detection=0) 
     cout<<" the device has never malfunctioned"; 
    else 
     cout<<"The device has malfunctioned"<<Num_Malfunction_Detection<<"times. the malfunction is type"<<Type_Malfunction<<" and last malfunction time is"<<Last_Malfunction<<endl; 
} 

int malfunctionRecord::getRecord(int*m,int*t) 
{ 
    cout<<"The device has malfunctioned"<<Num_Malfunction_Detection<<"times."; 
    Type_Malfunction=*m; 
    Last_Malfunction=*t; 
} 

/*int device::device(char*n,int sn) 
{ 

} 

void device::display() 
{ 

} 

void device::recordMalfunction(int m,int t) 
{ 

} 

int device::getMalfunctionRecord(int *m,int *t) 
{ 

} 

int device::amIThisDevice(char*n) 
{ 

} 
*/ 

(これは私のメインのCPPファイルで、与えられた)

#include "definitions.h" 
#include "devices.h" 
#include <iostream> 

using namespace std; 


int main() { 

malfunctionRecord m1, m2; 
device d1("Turn Signal Lever", 195), d2("Accelerator", 247), *d3; 
int c, m, t;   // Temp variables to hold values retrieved from getRecord. 
char ch;    // Used to hold display until user presses enter. 

// malfunctionReport tests. 
cout << "Initially both m1 and m2 should have no malfunctions:\n\n"; 
m1.display(); 
cout << "\n"; 
m2.display(); 
cout << "\n"; 

// Set a malfunction in m1. 
m1.malfunction(MALFUNCTION_UNDER_RANGE,10); 
cout << "m1 should now have one malfunction with time 10 and under range.\n"; 
m1.display(); 
// Now add some malfunctions and verify that only the last is kept. 
m1.malfunction(MALFUNCTION_OVER_RANGE,25); 
cout << "\nm1 should now have two malfunctions, the last one with time 25 and over range.\n"; 
m1.display(); 
m1.malfunction(MALFUNCTION_STOPPED_WORKING,32); 
cout << "\nm1 should now have three malfunctions, the last one with time 32 and stopped working.\n"; 
m1.display(); 

// Now test the retrieval function. 
c = m1.getRecord(&m, &t); 
cout << "\n\nValues returned from getRecord are " << c << ", " << m << ", and " << t << ".\n"; 
cout << "\nEnd of malfunctionReport tests.\n\n\n"; 

// Hold display so user has a chance to check results so far. 
cout << "Press ENTR when ready to continue:"; 
ch = cin.get(); 



// device class tests. 
cout << "\n\n\nBeginning tests for device class.\n"; 
cout << "Display original d1 and d2:\n\n"; 
d1.display(); 
cout << "\n"; 
d2.display(); 
cout << "\n\nTest the amIThisDevice function. \n"; 

if(d1.amIThisDevice("Turn Signal Lever")) cout << " First test on d1 passed.\n"; 
else          cout << " First test on d1 failed.\n"; 

if(d1.amIThisDevice("Accelerator")==0)  cout << " Second test on d1 passed.\n"; 
else          cout << " Second test on d1 failed.\n"; 

cout << "\n\nNow test record and get malfunction function members.\n"; 
d1.recordMalfunction(MALFUNCTION_UNDER_RANGE,25); 
cout << " Should see count equal 1 and under range malfunction at time 25:\n"; 
d1.display(); 
d1.recordMalfunction(MALFUNCTION_OVER_RANGE,50); 
cout << "\n Should see count equal 2 and over range malfunction at time 50:\n"; 
d1.display(); 
d1.recordMalfunction(MALFUNCTION_STOPPED_WORKING,64); 
cout << "\n Should see count equal 3 and stopped working malfunction at time 64:\n"; 
d1.display(); 
cout << "\n\nTry to retrieve malfunction report. Should see same values as above.\n"; 
c = d1.getMalfunctionRecord(&m,&t); 
cout << "Values returned from getRecord are " << c << ", " << m << ", and " << t << ".\n"; 

// Test destructor. Create a new device and then delete it. 
cout << "\n\nTesting create and destroy n object. If you don't see the"; 
cout << "\nend of tests message, there is something wrong with your destructor.\n\n"; 
d3 = new device("Temporary Device", 100); 
d3->display(); 
delete d3; 


cout << "\n\nEnd of tests for Program 3.\n"; 


return 0; 
} 

01私はそれをコンパイルするとき

(これは私のdefinition.hファイルです)

#define NO_MALFUNCTION         20 
#define MALFUNCTION_OVER_RANGE       21 
#define MALFUNCTION_UNDER_RANGE       22 
#define MALFUNCTION_STOPPED_WORKING      23 

、私はこれらのエラーを取得しておいてください。

g++ devices.cpp main.cpp -o a 
devices.cpp:9:23: warning: character constant too long for its type 
main.cpp: In function ‘int main()’: 
main.cpp:11: warning: deprecated conversion from string constant to ‘char*’ 
main.cpp:11: warning: deprecated conversion from string constant to ‘char*’ 
main.cpp:53: warning: deprecated conversion from string constant to ‘char*’ 
main.cpp:56: warning: deprecated conversion from string constant to ‘char*’ 
main.cpp:76: warning: deprecated conversion from string constant to ‘char*’ 
Undefined symbols for architecture x86_64: 
    "device::device(char*, int)", referenced from: 
     _main in cc7F618W.o 
    "device::display()", referenced from: 
     _main in cc7F618W.o 
    "device::amIThisDevice(char*)", referenced from: 
     _main in cc7F618W.o 
    "device::recordMalfunction(int, int)", referenced from: 
     _main in cc7F618W.o 
    "device::getMalfunctionRecord(int*, int*)", referenced from: 
     _main in cc7F618W.o 
    "device::~device()", referenced from: 
     _main in cc7F618W.o 
ld: symbol(s) not found for architecture x86_64 
collect2: ld returned 1 exit status 

誰もが私のコードで間違っているものを私に伝えることができますか?ありがとう!

+0

メンバ関数の実装を記述するときに、私がmalfunctionRecord :: getRecord(int * m、int * t)に対して正しく記述するかどうかわかりません。誰も私がコードを修正するのを助けることができますか?ありがとう –

答えて

2

devices.cpp(下の5つ)に関数定義の束をコメントアウトしました。彼らはまだヘッダーにあります。

これは、シンボルを通知してからそれを定義しないと不平を言うリンカです。

関数を定義するか、関数への参照をすべて削除します。

関連する問題