0

This is my situation:

class foo{
public:
    class bar{
        friend bar operator+(const bar & , int i);
    }
};
foo::bar operator+(const foo::bar & , int i){
   ...
}

if i compile this i get an error Undefined symbols for architecture x86_64... so what i've done is this:

foo::bar operator+(const bar & , int i);
class foo{
public:
    class bar{
        friend bar operator+(const bar & , int i);
    }
};
foo::bar operator+(const foo::bar & , int i){
   ...
}

But now is the declaration that doesn't know what is foo::bar so i've added this:

class foo{
public:
    class bar;
}
foo::bar operator+(const bar & , int i);
class foo{
public:
    class bar{
        friend bar operator+(const bar & , int i);
    }
};
foo::bar operator+(const foo::bar & , int i){
   ...
}

But now is telling me that i'm redefining the class foo, how can i solve this?

Also tried

class foo::bar;

at the beginning, but it doesn't work

Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48
  • Unfortunately, you cannot forward-declare inner classes in C++. You have to un-nest one of the inner classes, so that it can be declared independently. Maybe replace the inner class with a `typedef`, so as far as the class is concerned, it's an inner class. – Sam Varshavchik Apr 25 '20 at 23:29
  • Forward declaration issues will cause compile-time errors, not link-time errors about "undefined symbols". The examples you show (obviously not actually tried) don't explain that piece. – aschepler Apr 25 '20 at 23:38

0 Answers0