我有gdb 7.6和g ++ 4.8.3的問題。我有以下3個文件在內部類GDB中的不完整類型與虛擬方法定義在一個單獨的文件
main.h
class A {
public:
class B {
public:
virtual ~B();
virtual void f();
int abc;
};
};
b.cpp
#include "main.h"
A::B::~B() {}
void A::B::f() {}
的main.cpp
#include "main.h"
int main()
{
int a=0;
A::B x;
A::B *y = &x;
a = 10;
return a;
}
然後
>> g++ main.cpp b.cpp -o main -g
>> gdb ./main
GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/gdb/main...done.
(gdb) b 8
Breakpoint 1 at 0x400654: file main.cpp, line 8.
(gdb) r
Starting program: /tmp/gdb/main
Breakpoint 1, main() at main.cpp:8
8 a = 10;
(gdb) p *y
$1 = <incomplete type>
我們沒有問題,如果
- 這些方法的定義是在main.h.
- 該方法是虛擬的。
這是一個已知的問題嗎?如何解決該問題?
也許嘗試使用鐺/ LLDB呢? – xaxxon
相關問題:http://stackoverflow.com/q/29494132/72178 – ks1322
鏈接建議-g。我在我的情況下使用-g,仍然有同樣的錯誤。 –