forward-declaration

Forward declaration of nested enum

Hi all, I have code similar to the following: class B { } class A { enum { EOne, ETwo } EMyEnum; B myB; } I want to declare a member of type EMyEnum in class B (which is declared before A). Is this possible? I realise the solution is to declare class B second, but for clarity I would prefer not to. ...

"using typedef-name ... as class" on a forward declaration

I'm doing some policy-based designs here and I have the need to typedef lots of template types to shorten the names. Now the problem comes that when I need to use a pointer to one of those types I try to just forward-declare it but the compiler complains with a test.cpp:8: error: using typedef-name ‘Test1’ after ‘class’ It's nothing to ...

Object construction/Forward function declaration ambiguity

Observation: the codes pasted below were tested only with GCC 4.4.1, and I'm only interested in them working with GCC. Hello, It wasn't for just a few times that I stumbled into an object construction statement that I didn't understand, and it was only today that I noticed what ambiguity was being introduced by it. I'll explain how to ...

Refactoring C++ code to use forward declarations

I've got a largeish codebase that's been around for a while and I'm trying to tidy it up a bit by refactoring it. One thing I'd like to do is find all the headers where I could forward declare members, instead of including the entire header file. This is a fairly labour intensive process and I'm looking for a tool that could help me fi...

Forward declare a global type inside a namespace

Hello, I want to use an 3rd party library without using its header file. My code resides in its own namespace, therefore I can't use conventional forward declaration as I don't want to pollute the global namespace. Currently I have something like that: 3rd-party-library.h---- typedef struct {...} LibData; void lib_func (LibData *); m...

Cocoa: Build Warning that s Forward Declared Class's and @interface May not Exist

I am trying to build the Clustering Plug in my project under Leopard. I have following two questions. In the project an interface class is defined as @interface ClusteringController : NSWindowController { ....... ..... .... } @end. And this class is used in implementation class using forward declaration: @class ClusteringController...

Java: Forward declarations of classes in namespaces

How do I do forward declarations in Java? I have two classes, each needs to call a method in the other and they both reside within different namespaces. For example... package one; class A { public void foo() { B b = new B(); b.bah(); } } and package two; class B { public void bah() { A a = new ...

forward declare typedef'd struct

I can't figure out how to forward declare a windows struct. The definition is typedef struct _CONTEXT { .... } CONTEXT, *PCONTEXT I really don't want to pull into this header, as it gets included everywhere. I've tried struct CONTEXT and struct _CONTEXT with no luck (redefinition of basic types with the actuall struct in winn...

Compiling C++ when two classes refer to one another

I am trying to write a simple wrapper around a connection pointer that will return it to the pool when the wrapper is destroyed, but it wont compile because the ConnectionPool and AutoConn need each other to be declared. I tried to use forward deceleration but it didn't work. How do I solve this? (using g++) class Connection {}; class...

Why, really, deleting an incomplete type is undefined behaviour?

Hi, consider this classic example used to explain what not to do with forward declarations: //in Handle.h file class Body; class Handle { public: Handle(); ~Handle() {delete impl_;} //.... private: Body *impl_; }; //--------------------------------------- //in Handle.cpp file #include "Handle.h" class Bod...

Any way in C++ to forward declare a function prototype?

I make regular use of forward class declarations and pointers to such classes. I now have a need to pass a function pointer through a number of layers. I would prefer to include the header that declares my function pointer's prototype only into the module that dereferences a function pointer rather than into each layer that simply passe...

C++ nested class/forward declaration issue

Is it possible to forward-declare a nested class, then use it as the type for a concrete (not pointer to/reference to) data member of the outer class? I.E. class Outer; class Outer::MaybeThisWay // Error: Outer is undefined { }; class Outer { MaybeThisWay x; class MaybeThatOtherWay; MaybeThatOtherWay y; // Error: MaybeThatOt...

C++ Forward declaration for virtual function

Hi, I have a class hierarchy and i am writing a virtual function in it. Say there are three classes class A { virtual A* test(); }; ( File A.h ) class B : public A { virtual C* test(); }; ( File B.h ) class C : public A {}; ( File C.h ) Now is it possible for me to avoid including C.h in B.h, by doing some kind of forward decl...

Header files inclusion / Forward declaration

Hi, In my C++ project when I have to go for the inclusion (#include "myclass.h") of header files?? And when I have to go for forward declaration of the class (class CMyClass;) ?? Any suggestions regarding this are welcome. ...

C++ forward declaration problem

Hi, I have a header file that has some forward declarations but when I include the header file in the implementation file it gets included after the includes for the previous forward declarations and this results in an error like this. error: using typedef-name ‘std::ifstream’ after ‘class’ /usr/include/c++/4.2.1/iosfwd:145: error: ‘st...

C++: How to use types that have not been defined?

C++ requires all types to be defined before they can be used, which makes it important to include header files in the right order. Fine. But what about my situation: Bunny.h: class Bunny { ... private: Reference<Bunny> parent; } The compiler complains, because technically Bunny has not been completely defi...

Using forward declarations for built in datatypes.

I understand that wherever possible we shall use forward declarations instead of includes to speed up the compilation. I have a class Person like this. #pragma once #include <string> class Person { public: Person(std::string name, int age); std::string GetName(void) const; int GetAge(void) const; private: std::string ...

OCaml forward declaration

Is there a way to do a C-style forward declaration in OCaml? My problem is that I have two variants which mutually refer to each other: type path_formula = [ `Next of state_formula | `Until of (state_formula * state_formula) | `UntilB of (state_formula * int * state_formula) ] type state_formula = [ `True | `False |...

C++ namespace alias and forward declaration

I am using a C++ third party library that places all of its classes in a versioned namespace, let's call it tplib_v44. They also define a generic namespace alias: namespace tplib = tplib_v44; If a forward-declare a member of the library in my own .h file using the generic namespace... namespace tplib { class SomeClassInTpLib; } ......

C++: Unknown pointer size when forward declaring (error C2036)

In a header file, I have forward declared two members of a namespace: namespace Foo { struct Odp typedef std::vector<Odp> ODPVEC; }; class Bar { public: Foo::ODPVEC baz; // C2036 }; The error generated by the compiler is: error C2036: 'Foo::Odp *': unknown size I'm guessing this is an issue with forward declaring Odp....