建筑x86_64的未定义符号。我的代码有什么问题?
Undefined symbols for architecture x86_64. what's wrong with my codes?
devices.h文件
#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
(这是我的.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:nn";
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 << "nnValues returned from getRecord are " << c << ", " << m << ", and " << t << ".n";
cout << "nEnd of malfunctionReport tests.nnn";
// 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 << "nnnBeginning tests for device class.n";
cout << "Display original d1 and d2:nn";
d1.display();
cout << "n";
d2.display();
cout << "nnTest 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 << "nnNow 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 << "nnTry 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 << "nnTesting create and destroy n object. If you don't see the";
cout << "nend of tests message, there is something wrong with your destructor.nn";
d3 = new device("Temporary Device", 100);
d3->display();
delete d3;
cout << "nnEnd 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
有人能告诉我我的密码出了什么问题吗?谢谢
您在devices.cpp
中注释掉了一堆函数定义(底部的五个)。他们仍然在头部。
这是链接器抱怨你通知它一个符号,然后没有定义它
要么定义函数,要么删除对它们的所有引用。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 0-1背包代码中的错误.我的代码中有什么错误
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我需要C++中不同的排序格式来对这个USACO代码上的数组和优先级队列进行排序
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 是否值得降低我的代码的可读性,以便在出现内存不足错误时提供异常安全性?
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- 无法在我的堆排序代码中找到错误.无法正确执行.C++
- 如何重写全局方法名称以在调用原始方法之前将我的代码推到前面
- 为什么我的 BaseClass:Method 代码编译(带有单冒号)?
- 我的代码运行良好,但在游戏循环中中断
- 8谜题代码.我的队列没有填充,我找不到错误的位置