Search code examples
c++syntaxcompiler-errorsforward-declaration

C++: Unknown pointer size when forward declaring (error C2036)


In a header file, I have forward declared two members of a namespace:

namespace Foo {
    struct Odp; 
    typedef std::vector<Odp> ODPVEC;
};

class Bar
{
public:
     Foo::ODPVEC baz; // C2036
};

The error generated by the compiler is:

error C2036: 'Foo::Odp *': unknown size

I'm guessing this is an issue with forward declaring Odp. How can I get around this?


Solution

  • Don't forward declare Odp. The compiler does not know what the type of std::vector<Odp> is, because Odp isn't yet declared. Give the compiler a full declaration for that class.