MiLu
MiLu

Reputation: 25

How can I define a struct in (*.cpp) instead (*.h) in a class

I want to define a struct out of the head file.

Below is what I declare in the (*.h)

class MyVertex
{
public:
    struct Vertex{};
};

How can I define the struct Vertex more detailedly in the (*.cpp)? I've tried several times with several ways but failed.

Upvotes: 2

Views: 823

Answers (1)

JaredPar
JaredPar

Reputation: 755179

The problem here is you are not declaring the struct you are fully defining it. In order to declare it you need to leave off the {}

class MyVertex { 
public:
  struct Vertex;
};

Once you do that you will be able to define the struct members later in the .h file or the .cpp

struct MyVertex::Vertex { 
  ...
};

Upvotes: 7

Related Questions