我遇到了在netbeans中构建和运行单元测试的问题。错误在上面的标题以及下面的转储中。[在此处输入图像描述] [1]
build/Debug/Cygwin-Windows/Device.o: In function `Device::Device()':
/cygdrive/c/Users/Sam/Documents/NetBeansProjects/Rover/Device.cpp:11:
undefined reference to 'Battery::Battery()'
/cygdrive/c/Users/Sam/Documents/NetBeansProjects/Rover/Device.cpp:11:(.text+0x26): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Battery::Battery()'
我在代码中的不同行收到三个相同的错误:
#include "Device.h"
Battery _battery; //error here
Device::Device() //error here
{
}
Device::Device(const Device& orig) { //error here
}
Device::~Device() {
}
void Device::operate()
{
}
Battery Device::getBattery()
{
return _battery;
}
设备头文件 - >
#include "Battery.h"
#ifndef DEVICE_H
#define DEVICE_H
class Device {
public:
Device();
Device(const Device& orig);
virtual ~Device();
virtual void operate();
Battery getBattery();
//bool connectBattery();
//bool disconnectBattery();
private:
Battery _battery;
};
#endif /* DEVICE_H */
Battery.cpp
#include "Battery.h"
int _power;
Battery::Battery(int power)
{
_power=power;
}
Battery::Battery(const Battery& orig)
{
}
Battery::~Battery()
{
}
bool Battery::Charge(int pUnit)
{
_power += pUnit;
return true;
}
bool Battery::Discharge(int pUnit)
{
_power -= pUnit;
return true;
}
BATTERY.H
#ifndef BATTERY_H
#define BATTERY_H
class Battery {
public:
Battery();
Battery(int power);
Battery(const Battery& orig);
virtual ~Battery();
bool Charge(int pUnit);
bool Discharge(int pUnit);
private:
int _power;
};
#endif /* BATTERY_H */
任何帮助都会很棒,我已经暂时抛弃这个问题了...... 编辑:我也在用Alt-F6 + cppunit测试
测试项目