[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

forward declare classes?

Posted on 2004-10-25
3
Medium Priority
?
241 Views
Last Modified: 2010-05-18
if i have:

class first
{
  first()
  {
     second _s = second();
  }
};

class second
{
  second()
  {
   
  }
};

//

_s cannot be made, because 'class second' hasnt been looked at yet?....
apart from reordering them, how can i make this work?
0
Comment
Question by:rfterdarc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
HendrikTYR earned 396 total points
ID: 12399257
You may do it like this:

 class first
 {
 public:
     first();
 };

class second
{
public:
  second()
  {
   
  }
};

first::first() {
    second _s = second();
}

ie. You may still first declare "first", but make sure that your declaration of second is then "included" before you use "second".

You may also do this:

class second; // The forward reference.

 class first
 {
 public:
     second *s;
     first();
 };

class second
{
public:
  second()
  {
   
  }
};

Here you declare that second will be a class.  Because you only declare a "second" pointer in class "first", the compiler does not need to know the exact size of "second" when it compiles the implementation of class "first"

Hope a combination of these will solve your problems

Regards
Hendrik
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question