forward-declaration

Forward declaration problem

I'm using C++ .NET 2.0 I have 2 forms the first one is declared as follow #include "stdafx.h" namespace myNamespace{ public ref class frmMain : public System::Windows::Forms::Form { /*... snip ...*/ public void addNewRow(String^ text){ /*... snip... */ } public void launchSubForm() { SubForm^ sf = gcnew S...

When to use forward declaration?

I am looking for the definition of when I am allowed to do forward declaration of a class in another class's header file: Am I allowed to do it for a base class, for a class held as a member, for a class passed to member function by reference, etc. Thank you. ...

Templates: Use forward declarations to reduce compile time?

I have to deal with a library that consists of many templated classes, which are of course all implemented in header files. Now I'm trying to find a way to reduce the unbearably long compile times that come from the fact that I pretty much have to include the whole library in each and one of my compilation units. Is using forward declar...

Why do C++ templates let me circumvent incomplete types (forward declarations)?

I tried three iterations of the following simple program. This is a highly simplified attempt to write a container-and-iterator pair of classes, but I was running into issues with incomplete types (forward declarations). I discovered that this was in fact possible once I templatized everything - but only if I actually used the template...

Forward declare pointers-to-structs in C++

I am using a 3rd party library that has a declaration like this: typedef struct {} __INTERNAL_DATA, *HandleType; And I'd like to create a class that takes a HandleType in the constructor: class Foo { Foo(HandleType h); } without including the header that defines HandleType. Normally, I'd just forward-declare such a type, but I ...

Better way to forward declare typedef'd structures in C89?

struct SomeStruct; typedef struct SomeStruct SomeStruct; The above works, but is there a simpler (or better) way? ...

Forward reference vs. forward declaration

Im a bit confused. What is the difference between forward declaration and forward reference? Forward declaration is, in my head, when you declare a function that isnt yet implemented, but is this incorrect? Do you have to look at the specified situation for either declaring a case "forward reference" or "forward declaration"? ...

C++ Tricky Inheritance Class Definition Problem

Hello! I'm getting this error when dealing with a number of classes including each other: error: expected class-name before '{' token I see what is going on, but I do not know how to properly correct it. Here is an abstracted version of the code: A.h #ifndef A_H_ #define A_H_ #include "K.h" class A { public: A(); }; #...

Is it worth forward-declaring library classes?

I've just started learning Qt, using their tutorial. I'm currently on tutorial 7, where we've made a new LCDRange class. The implementation of LCDRange (the .cpp file) uses the Qt QSlider class, so in the .cpp file is #include <QSlider> but in the header is a forward declaration: class QSlider; According to Qt, This is another...

Forward declaration of a typedef in C++

Why won't the compiler let me forward declare a typedef? Assuming it's impossible, what's the best practice for keeping my inclusion tree small? ...

Forward declare a class's public typedef in c++

I'm trying to simplify a bunch of header file "include spaghetti" by using forward declarations and moving #includes into the implementation file. However, I keep coming upon the following scenario: //Foo.h #include "Bar.h" class Foo { public: void someMethod(Bar::someType_t &val); }; //Bar.h . . . class Bar { public: typedef std...

Is the size of an object needed for creating object on heap?

When compiler need to know the size of a C (class) object: For example, when allocating a C on the stack or as a directly-held member of another type From C++ Coding Standards: 101 Rules, Guidelines, and Best Practices Does that mean for a heap allocated object, size is not necessary? Class C;//just forward declaration C * o...

Forward declaration of nested types/classes in C++

I recently got stuck in a situation like this: class A { public: typedef struct/class {...} B; ... C::D *someField; } class C { public: typedef struct/class {...} D; ... A::B *someField; } Usually you can declare a class name: class A; But you can't forward declare a nested type, the following causes compilation er...

How do I forward declare a delegate in C++/CLI?

How? The following did not work: delegate MyDelegate; ref class MyDelegate; delegate void MyDelegate; The following works for declaration: public delegate void MyDelegate(Object ^sender, MyArgs ^args); But using it as a forward declaration gives me error C3756: 'MyNameSpace::MyDelegate': delegate definition conflicts with an exi...

When is a forward declaration required?

I have this C++ project that I'm working on All classes have their implementation separated from the .h file. However, I'm not certain why/when forward declarations are required. For example, I just ran into an error when I #included "ClassType.h", the compiler completely refuses to compile a class that had a pointer to ClassType, eve...

Forward declaration in multiple source directory; template instantation

Hi, I am looking for a nice book, reference material which deals with forward declaration of classes esp. when sources are in multiple directories, eg. class A in dirA is forward declared in class B in dirB ? How is this done ? Also, any material for template issues, advanced uses and instantation problems, highly appreicated ? Thanks...

Forward declaration - no admin page in django?

Hi SO, This is probably a db design issue, but I couldn't figure out any better. Among several others, I have these models: class User(models.Model): name = models.CharField( max_length=40 ) # some fields omitted bands = models.ManyToManyField( Band ) and class Band(models.Model): creator = models.ForeignKey( User ) # some...

How do i forward declare a class that has been typedef'd?

I have a string class that, unsurprisingly, uses a different implementation depending on whether or not UNICODE is enabled. #ifdef UNICODE typedef StringUTF16 StringT; #else typedef StringUTF8 StringT; #endif This works nicely but I currently have a problem where I need to forward declare the StringT typedef. How can I do this? I ca...

C++ Class forward declaration drawbacks?

Hi! I want to use forward declaration of a class in my software, so I can have typedefs and use them inside the class full declaration. Smth like this: class myclass; typedef boost::shared_ptr<myclass> pmyclass; typedef std::list<pmyclass > myclasslist; class myclass : public baseclass { private: // private member declaration...

Is there a way to forward declare covariance?

Suppose I have these abstract classes Foo and Bar: class Foo; class Bar; class Foo { public: virtual Bar* bar() = 0; }; class Bar { public: virtual Foo* foo() = 0; }; Suppose further that I have the derived class ConcreteFoo and ConcreteBar. I want to covariantly refine the return type of the foo() and bar() methods like this: ...