2012-02-05 125 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; 
} 

(这是我的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

当写入成员函数的实现时,我不确定我是否正确写入了faultsRecord :: getRecord(int * m,int * t)。任何人都可以帮我纠正代码?谢谢 – 2012-02-05 23:11:04

回答

2

您在devices.cpp(最下面的五个)中注释了一堆函数定义。他们仍然在头上。

这是连接器抱怨你通知它一个符号,然后没有定义它。

可以定义函数或删除对它们的所有引用。

相关问题