473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

unfamiliar syntax: class MyClass;

I have seen this on the top of a few header files

class SomeClass;
What does it mean?
I would expect some sort of declaration or defintion following such as

class SomeClass
{
SomeClass();
~SomeClass();

void SomeFunc();
};

or

class SomeClass class_instance;

Jun 2 '06 #1
3 1681
<cp***@austin.rr.com> wrote:
I have seen this on the top of a few header files

class SomeClass;

What does it mean?


It's a forward declaration:

http://www.parashift.com/c++-faq-lit...html#faq-39.11

S.
Jun 2 '06 #2
cp***@austin.rr.com wrote:
I have seen this on the top of a few header files

class SomeClass;
What does it mean?


It is a "forward declaration" that tells the compiler that SomeClass is
a class name. That is enough information to compile a class declaration
that contains a pointer or reference to SomeClass.

class SomeClass;

class Other
{
SomeClass* pSome;
};

Notice that this header file can be compiled without needing to
#include "SomeClass"

This trick is needed if SomeClass contains a pointer for Other. The
forward reference lets you eliminate the circular includes.

--
Scott McPhillips [VC++ MVP]

Jun 2 '06 #3
cpisz wrote:
class SomeClass; What does it mean?


http://www.google.com/search?q=forward+declarations

It means the header file knows the class's name but not its size or members.

C++ code needs to see a class's body to know its size and members. If code
only needs the name (such as to declare a reference), then a header may omit
compiling the header containing that SomeClass, and thus omits every header
that header calls.

Forward declarations become important as a program grows because they
prevent small changes to rare headers from making everything recompile for
no reason. Google "compilation firewall".

If you see it right above its definition, someone was being officious
without adding value.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jun 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cppaddict | last post by:
Is it possible to avoid using push_back repeatedly when initializing a vector? That is, is there a vector syntax that would be analogous to the following array initialization syntax: MyClass...
4
by: Matthias Käppler | last post by:
Hi, in Nicolai Josuttis book about the C++ standard library, class templates are defined like this: template<class T> class MyClass<T> { T value; };
2
by: bor_kev | last post by:
Hi, First of all, i want to use the new managed class syntax and STL.NET under Microsoft Visual (C++) Studio 2005 Beta. I read in a Microsoft...
5
by: Rob | last post by:
To follow up on the "copy constructor clarification thread"... The assignment operator syntax shown previously: MyClass% operator=(const MyClass%); seems to have problems if you have member...
9
by: Bern McCarty | last post by:
I am porting stuff from MEC++ syntax to the new C++/CLI syntax. Something that we did in the old syntax that proved to be very valuable was to make sure that the finalizer would purposefully...
5
by: Sathyaish | last post by:
/* I am writing this C# program because I forgot the syntax for calling a parameterized constructor from a non-parameterized one within the same class. I was coding in Java and just typed it...
2
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hello, friends, I tried to have 2 classes in an abstract class, but could not figure out the syntax. I knew with 1 class the syntax is: public abstract class MyClass<Twhere T : class { } ...
2
by: berrylthird | last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example: var myInstance:myClass = new...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.