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

Separating Definition and Declaration of a class

As all we know, in order to remove cyclic includes in C++ we seperate
the declarations and definitions of classs and it's member in two files
Header (*.h) and source files (*.cpp). This is not a problem for C# as
there is no concept of include.

I faced problems for seperating declarations and definitions for class
when it contains [default]properties. This can also be done in context
of struct/structures. Here is how we can.

Class A

--------------------------------------
FILE : A.h <-- contains only declarations
--------------------------------------
namespace Ankit
{
public class A
{
private:
int mapData;

public:
property int Height ; // no need for definitions in
A.cpp
property int Width ; // no need for definitions in
A.cpp
property ArrayList^ Points
{
ArrayList^ get();
}
property double Zoom
{
double get();
void set(double level);
}
property int default[int]
{
int get(int index);
}

A();
void Load(double level);
}

}

--------------------------------------
FILE : A.cpp <-- contains implementaions
--------------------------------------
Note:- No need to write access specifiers again

namespace Ankit
{
ArrayList ^ A::Points::get()
{
return this->wayPoints ; // your
implementations
}

double A::Zoom::get() // get set functions should be
written
seperate
{
return 1.0;
}

void A::Zoom::set(double l)
{
;
}
int A::default::get(int index)
{
// your implementations
return this->wayPoints[index];
}

///<summary>
///Default Constructor
///</summary>
A::A()
{
// your implementations
}

void A::Load(double level)
{
//implementations
}
}

}

That's all.

Hope this may be usefull to u....

Regards.....

Ankit Jain
[Developers Have Their Own Gods]

Nov 17 '05 #1
1 1161
There is also the "#pragma once" command to insure the same include file
isn't referenced more than once if it happens to be in, say, two different
includes being used at the same time (which happens all the time)... : )

[==P==]

"AnkitAsDeveloper [Ankit]" <an**************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
As all we know, in order to remove cyclic includes in C++ we seperate
the declarations and definitions of classs and it's member in two files
Header (*.h) and source files (*.cpp). This is not a problem for C# as
there is no concept of include.

I faced problems for seperating declarations and definitions for class
when it contains [default]properties. This can also be done in context
of struct/structures. Here is how we can.

Class A

--------------------------------------
FILE : A.h <-- contains only declarations
--------------------------------------
namespace Ankit
{
public class A
{
private:
int mapData;

public:
property int Height ; // no need for definitions in
A.cpp
property int Width ; // no need for definitions in
A.cpp
property ArrayList^ Points
{
ArrayList^ get();
}
property double Zoom
{
double get();
void set(double level);
}
property int default[int]
{
int get(int index);
}

A();
void Load(double level);
}

}

--------------------------------------
FILE : A.cpp <-- contains implementaions
--------------------------------------
Note:- No need to write access specifiers again

namespace Ankit
{
ArrayList ^ A::Points::get()
{
return this->wayPoints ; // your
implementations
}

double A::Zoom::get() // get set functions should be
written
seperate
{
return 1.0;
}

void A::Zoom::set(double l)
{
;
}
int A::default::get(int index)
{
// your implementations
return this->wayPoints[index];
}

///<summary>
///Default Constructor
///</summary>
A::A()
{
// your implementations
}

void A::Load(double level)
{
//implementations
}
}

}

That's all.

Hope this may be usefull to u....

Regards.....

Ankit Jain
[Developers Have Their Own Gods]

Nov 17 '05 #2

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

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
8
by: newmans | last post by:
Perhaps one of the experts can straighten me out on this point... In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition, section 4.9, indicates that typedef complex<short>...
4
by: rajkirangrandhi | last post by:
Hi, I have several classes written in Java that I am trying to convert into C++. They are fairly simple classes, no gui stuff etc, just some math routines. I was able to do it without any problem....
2
by: Marc Mutz | last post by:
Hi, I'm currently wondering if and how you can separate definition from declaration of a full template specialisation. I have a UnitTest class that has an _assertEqual member template that I...
19
by: J. J. Farrell | last post by:
After many years of dealing with definition and linkage issues in ways that I know to be safe, I've decided it's time to try to understand this area properly. Consider a header file with the file...
2
by: xllx.relient.xllx | last post by:
I have a few quetions about definitions vs declarations concerning defined types (user defined), specifically classes. From what I understand, a class contained in a header file is a definition as...
14
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.