Error : Class A uses Class B, which is being defined

…衆ロ難τιáo~ 提交于 2020-01-24 13:42:09

问题


I have a C++ project that I've successfully wrapped with .NET classes using C++/CLI. I'm defining the wrapper classes in a .h file.

I'm currently getting Error C2460: Mixer uses Track, which is being defined.

As you can see in the code below, Mixer uses Track in the var MainTrack and Track also uses Mixer in the var Parent. How do I get these 2 classes linked to each other and compile successfully?

#ifndef CPP_MIXER_NET_H
#define CPP_MIXER_NET_H


#pragma managed



// Mixer class
public ref class Mixer {
private:
    void Create();
    void Destroy();

public:

    // props
    Track MainTrack;

    Mixer();
    ~Mixer();
    !Mixer();

};


// Track class
public ref class Track {
private:
    void Create(Track^ parent);
    void Destroy();


public:

    // props
    Mixer Parent;
    Track Parent;

    // public constructor
    Track(Track^ parent);
    ~Track();
    !Track();

};



#endif

回答1:


Just declare your classes at the very top:

public class Mixer;
public class Track;


来源:https://stackoverflow.com/questions/15611547/error-class-a-uses-class-b-which-is-being-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!