简体   繁体   中英

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.

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 { 
  ...
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM