小编Dav*_*vid的帖子

具有 C++ 虚函数时的 GDB 不完整类型

我刚刚注意到一些奇怪的事情,当我在类中添加“虚拟关键字”(除构造函数之外的任何函数)时,我无法在 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)

c++ debugging virtual gdb

3
推荐指数
1
解决办法
3339
查看次数

标签 统计

c++ ×1

debugging ×1

gdb ×1

virtual ×1