Return ENUM(defined in one class) from member function of other class

StackOverflow https://stackoverflow.com/questions/23576636

  •  19-07-2023
  •  | 
  •  

Вопрос

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