문제

I have this code

#include <iostream>
class A;

using namespace std;


class C {
    A::B fun(){
    }
};

class A{
    public:
    enum B {b1};
};


int main()
{

}

This code gives me an error main.cpp:8:5: error: ‘B’ in ‘class A’ does not name a type.

Does anyone know how to return A::B without moving A to top?

도움이 되었습니까?

해결책

Q Does anyone know how to return A::B without moving A to top?

A That is not possible.

Forward declaration of A does not give any details of what's inside the A. Hence, A::B is not a known type in class C.

In order to use A::B in class C, you have to put the complete definition of class A before the definition of class C starts.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top