PDA

View Full Version : Odd Syntax



acxdotfm
24th October 2008, 21:03
I haven't coded C++ in around five years so is it some sort of new syntax convention when you do this in your header files, or is it a QT thing?

/// somefile.h

#include <QLibrary>

class Classname;
class SomeOtherClassname;

class YourClass {
private:
// etc
public:
//etc
};

The bold underlined part is the one that's new to me.

caduel
24th October 2008, 21:22
These are forward declarations.
You tell the compiler that those types are classes.
This is enough to use the type in declarations, define pointers or references to the type.
(It is not enough to derive from the type, or use it in another manner that requires knowledge about its size, its methods or any other things that are defined by a class definition.)

Reason: you do not have to include the header where that class is defined.
Thus you avoid a dependency and get quicker compile times.

HTH

JimDaniel
24th October 2008, 21:23
That's a forward declaration (http://www.devx.com/tips/Tip/12583) - its not just a Qt thing.