Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top