Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-18-2008, 01:42 PM
radel radel is offline
Newbie
 
Join Date: Apr 2008
Posts: 1
Rep Power: 0
radel is on a distinguished road
Default How to declare two classes that have a pointer n between?

Hello there,

Im new in C++ programming, and i ve some troubles that ive never seen in other languages.

I ve two classes, and each one has a pointer to the other:

class C1{
public: C2* pointerC2;

}

class C2{
public: C1* pointerC1;
}

Well, the compiler cannot parse it, i think its cause C2 is not visible for C1 in compiling time. In fact, for C1, C2 its not yet declare.

What can i do, please?

Thank you, and excuse my very bad english.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-18-2008, 03:33 PM
dcs dcs is offline
Programming Expert
 
Join Date: Mar 2008
Posts: 371
Rep Power: 6
dcs has a spectacular aura aboutdcs has a spectacular aura about
Default Re: How to declare two classes that have a pointer n between?

Use a forward declaration.
Code:
class C2; // forward declaration
class C1{
public: C2* pointerC2;

};

class C2{
public: C1* pointerC1;
};
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 03:00 PM
nutario's Avatar   
nutario nutario is offline
Newbie
 
Join Date: Mar 2008
Location: Germany
Posts: 23
Rep Power: 3
nutario is on a distinguished road
Send a message via ICQ to nutario Send a message via Skype™ to nutario
Default Re: How to declare two classes that have a pointer n between?

Quote:
Originally Posted by dcs View Post
Use a forward declaration.
Code:
class C2; // forward declaration
class C1{
public: C2* pointerC2;

};

class C2{
public: C1* pointerC1;
};
Edit: in both haeders!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-20-2008, 02:18 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,897
Last Blog:
Web slideshow in JavaS...
Rep Power: 78
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: How to declare two classes that have a pointer n between?

Ja - das denke ich!
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
function pointer Chinmoy C Tutorials 0 03-19-2008 01:52 AM
Classes sthenri Java Help 2 12-06-2007 08:16 AM
Pseudo + Pointer diagram, Help from the masters borny86 Pascal/Delphi 2 11-30-2007 06:22 PM
Derived Classes Can't Set Function Pointers dargueta C and C++ 11 11-05-2007 10:04 PM
Issue writing to file: pointer to a class which contains pointers to other classes Sheemer C and C++ 0 08-21-2007 02:17 AM


All times are GMT -5. The time now is 10:50 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads