C++ - 2 classes 1 file

后端 未结 8 2020
南旧
南旧 2021-01-19 03:11

Suppose I want something of this sort, in one .cpp source file:

class A {
    public:
        void doSomething(B *b) {};
};

class B {
    publi         


        
8条回答
  •  悲&欢浪女
    2021-01-19 03:38

    Yes. You need a forward declaration:

    class B; // add this line before A's declaration
    
    class A {
        public:
            void doSomething(B *b) {};
    };
    
    class B {
        public:
            void doSomething(A *a) {};
    };
    

提交回复
热议问题