我刚刚注意到一些奇怪的事情,当我在类中添加“虚拟关键字”(除构造函数之外的任何函数)时,我无法在 GDB 中显示对象的内容。GDB 说“不完整类型”
这是代码:
////////////////reco.h //////////////
#ifndef RECO_H
#define RECO_H
#include <iostream>
#include <string>
class reco {
public:
reco(float weight);
~reco(void);
float getWeight();
private:
float weight;
};
#endif
Run Code Online (Sandbox Code Playgroud)
/////////////////reco.cpp //////////////
#include <iostream>
#include <string>
#include "reco.h"
using namespace std;
reco::reco(float weight) {
weight = weight;
}
reco::~reco(void) {
cout << "destructor reco" << endl;
}
float reco::getWeight() {
return weight;
}
Run Code Online (Sandbox Code Playgroud)
////////////// main.cpp //////////////
#include <iostream>
#include <string>
#include "reco.h"
using namespace std;
int main() {
reco* s = …Run Code Online (Sandbox Code Playgroud)