I use a forward enum declaration in my cpp program that is causing gdb to give me an incompatible type. Here is a minimal working example:
definitions.h:
/*definitions.h*/
#ifndef DEFINITIONS_H_
#define DEFINITIONS_H_
enum ForwardEnum : int;
typedef ForwardEnum ForwardEnum;
typedef struct {
const ForwardEnum EnumValue;
} ElemConfig;
#endif //DEFINITIONS_H_
config.h:
/*config.h*/
#ifndef CONFIG_H_
#define CONFIG_H_
#include "definitions.h"
enum ForwardEnum : int {
EnumValue1 = -1,
EnumValue2,
};
#endif //CONFIG_H_
classA.h:
/*classA.h*/
#ifndef CLASSA_H_
#define CLASSA_H_
#include <array>
#include "definitions.h"
#define N_ELEMS 8
class A{
private:
const std::array<ElemConfig, N_ELEMS> Config;
public:
A(const std::array<ElemConfig, N_ELEMS>);
};
#endif //CLASSA_H_
main.cpp:
/*main.cpp*/
#include <iostream>
#include <array>
#include "definitions.h"
#include "config.h"
#include "classA.h"
const std::array<ElemConfig, N_ELEMS> AConfig {{{EnumValue1}}};
A::A(const std::array<ElemConfig, N_ELEMS> Config) : Config(Config)
{
ForwardEnum a = Config[0].EnumValue;
std::cout << a << std::endl;
};
int main(void)
{
A objectA(AConfig);
}
When I try to debug the class A constructor in gdb I get an incomplete type for the enum variable. According to this question I tried casting it to what I think is the compatible type:
print (ForwardEnum) a
When that failed I experimented to see if the problem was the typedef:
print (const enum ForwardEnum) a
And also to disassemble the constructor, but it all failed.
What is then the correct type conversion to print the content of EnumValue?
(Or, alternatively, How can I get gdb to resolve the incompatible type, while keeping the forward declaration?)
I am using gdb 7.7.1 and gcc 4.8.4