473,796 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1698
<cp***@austin.r r.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 "compilatio n 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
7535
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 myArray = { MyClass("Stan"), MyClass("Julie") }; Thanks for any ideas,
4
1167
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
1894
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 article(http://msdn.microsoft.com/VISUALC/default.aspx?pull=/library/en-us/dnvs05/html/stl-netprimer.asp) that i am suposed to include : #include <cli/vector> #include <algorithm>
5
1463
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 properties that need to be copied from the rhs to the lhs. Since the rhs parameter is "const MyClass", you get an error C2662 "'MyClass::prop::get' : cannot covert 'this' pointer from 'const MyClass' to 'MyClass %'" if you have code inside like
9
2333
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 generate an assertion failure for unoptimized, debug builds. We did this to find and fix cases where we were relying upon finalization rather than pro-active Dispose() calls. For classes that introduced IDisposable() into the class hierarchy...
5
2204
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 like this: public MyClass(String someParam) { }
2
1764
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 { } Then I tried both
2
5217
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 myClass(); myInstance.member_0 = memberValue_0; // absolute notation myInstance = memberValue_0; // relative notation myInstance = memberValue_0; // nominal notation You can initialize a struct in C/C++ like you would an array, as with the...
21
2467
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 type is not a single identifier or keyword. Which one is correct? For example: unsigned long x = unsigned long(y); REH
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10453
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.