jeudi 6 février 2020

Forward declaration of a class/struct defined within the scope of another class [duplicate]

I have a class definition that looks like:

// File: OuterClass.h
class OuterClass{
  public:
  // Member variables
  struct OuterClassActions {
    //members of OuterClass::OuterClass
  };
};

Now if I were to forward declare OuterClass in some other header, it'd be straight forward. i.e.,

// File: Utils.h
class OuterClass

And then can declare functions that operate on the objects of OuterClass. What I want is to be able to forward declare OuterClassActions and be able to use that in function declarations.

Something to the effect of:

// File: Utils.h

// forward declare (Note OuterClass::OuterClassActions can't
// be used as OuterClass is an incomplete type.
struct OuterClassActions; 

// Declare a function having argument type as declared above.
void myUtilFunction(OuterClass::OuterClassActions a);

Is there any way for me to do this, without modifying the structure of outerclass.h

Aucun commentaire:

Enregistrer un commentaire