Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2005

Tip: Looking for answers? Try searching our database.

Separating Definition and Declaration of a class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AnkitAsDeveloper [Ankit] - 25 Oct 2005 11:37 GMT
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]
Peter Oliphant - 25 Oct 2005 22:43 GMT
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==]

> 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
[quoted text clipped - 96 lines]
> Ankit Jain
> [Developers Have Their Own Gods]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.