473,804 Members | 3,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Seperating 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(do uble 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
0 983

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

Similar topics

7
2406
by: CoolPint | last post by:
I read that there has to be only one definition of classes, functions, etc. in a project. I just realized I might have broken the rule by defining the exception classes in the header file. But my linker does NOT complain. For example, Let's say I have a header file somewhat like below // MyClass.h class MyClassException1 {};
3
3618
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 non-standard C++ or if the problem lies elsewhere. To summarize static const class members are not being accessed properly when accessed from a DLL by another external object file (not within the DLL). It only occurs when the static const...
8
2460
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> Point; is not only a declaration, but also a definition. The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2 that
14
2875
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
19
2922
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 scope declaration int i; This header is included in two files that refer to i but do not declare it. The two files build together into a single program.
2
2697
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 a whole, but the contents a.k.a members, are the declarations (non-inline functions). What I'm trying to understand, is, is storage allocated or not allocated for them at this phase? Next, the members implemented in a .cpp file, for the class,...
8
1706
by: caferias | last post by:
Hello, I'm curious about the difference between the term "declaration" and "definition" in the context of XML. Where is the difference? Greetings: Fernando
9
8903
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 *defined* "x"'s value to be 10, isn't above statement a
10
2062
by: Danigan | last post by:
It's been about 4 years since I did much in C++. To see if I remembered anything, I made a new project, made a header file containing a class, included the header file from my main file, used pointers to dynamically allocate memory for a user-indicated number of class instances, and it was great! Now... I used to always be sure to seperate my definition and declaration files. What I have is below and it works, BUT I would like to have three...
0
9705
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
10567
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
10310
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
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
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
7613
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
6847
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();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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

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.