c++ - How do I forward declare an inner class? -


possible duplicate:
forward declaration of nested types/classes in c++

i have class so...

class container { public:     class iterator {         ...     };      ... }; 

elsewhere, want pass container::iterator reference, don't want include header file. if try forward declare class, compile errors.

class container::iterator;  class foo {     void read(container::iterator& it); }; 

compiling above code gives...

test.h:3: error: ‘iterator’ in class ‘container’ not name type test.h:5: error: variable or field ‘foo’ declared void test.h:5: error: incomplete type ‘container’ used in nested name specifier test.h:5: error: ‘it’ not declared in scope 

how can forward declare class don't have include header file declares iterator class?

this not possible. cannot forward declare nested structure outside container. can forward declare within container.

you'll need 1 of following

  • make class non-nested
  • change declaration order nested class defined first
  • create common base class can both used in function , implemented nested class.

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -