473,394 Members | 1,700 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,394 software developers and data experts.

object of the class inside its definition?

84
Is it possible to put an object of class inside a class? What I mean isexmplified in this code:
Expand|Select|Wrap|Line Numbers
  1. class  Spline : public Mathobject, AnchorEnabled {
  2. public:
  3. //(...)
  4.  Spline *mother;
  5. //(...)
  6.  
Is maybe possible becuase there is redundant inclusion of a header file: the header file includes itself, it's called spline.h and at the start you have a:
Expand|Select|Wrap|Line Numbers
  1. #include<spline.h>
Mar 23 '07 #1
2 1369
DeMan
1,806 1GB
You can declare an instance of a class inside itself (very useful for most data structures).
One of the ways you can get around problems this might cause in teh .h being included multiple times is to put in a failsafe....

in Spline.h, surround exerything in the file with:
Expand|Select|Wrap|Line Numbers
  1. #ifndef _SPLINE_H
  2. #define _SPLINE_H
  3.  
  4. /* Do all the normal things here */
  5.  
  6. #endif
  7.  
This means when Spline.h is included for the first time you set a value to show that you have already declared this header, and it won't be declared again.
Mar 23 '07 #2
sanctus
84
You can declare an instance of a class inside itself (very useful for most data structures).
But why is it useful? I mean if the compiler doesn't read twice the definition of the class it does not know what and object of type spline is.
One of the ways you can get around problems this might cause in teh .h being included multiple times is to put in a failsafe....

in Spline.h, surround exerything in the file with:
Expand|Select|Wrap|Line Numbers
  1. #ifndef _SPLINE_H
  2. #define _SPLINE_H
  3.  
  4. /* Do all the normal things here */
  5.  
  6. #endif
  7.  
This is already done, it's not me who is writing the program I'm trying to understand it, but thanks for the clarification.
Mar 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lüpher Cypher | last post by:
Ok, here's what I'm trying to do. I have a class. Inside the class I have a method that reads a text file. In the text file I have a class name and a file name where that class is defined. Now, I...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
1
by: Jianli Shen | last post by:
Hi, I want to implement like this: class A{ int length; class B{ void operate_length_in_A(){
5
by: ganesh.gella | last post by:
Hi All, Wanted to make sure on this, I have some functions for which I am providing the definition inside the class definition. (As these are very small functions like get and set). Do i...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
13
by: andrea | last post by:
Sorry for the stupid question, I know, but sometimes is necessary starts from the basic. I don't know how to pass the result of a method generated from a DAL class to a BL class returning the...
2
by: jordanp | last post by:
Hello, I'm having a little trouble here and I'm hoping that somebody might be able to help me out (win32 console program). First off, I know that I can use class function inside of my struct as...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
4
by: subramanian100in | last post by:
Consider the program #include <iostream> using namespace std; class Test { public: Test(Test_int c_value)
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...

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.