• Advertisement

Archived

This topic is now archived and is closed to further replies.

Predefining classes

This topic is 5903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I have 2 classes A and B, for some B mustbe able to see A and A must be able to see B for the purpose of operator overloading. An example:
  
class A
{
 public:
  double c;
  const void operator= (const B& b)
  {
    c = b.d;
  }
};

class B
{
 public:
  float d;
  const void operator= (const A& a)
  {
    d = (float)a.c;
  }
};

  
of course you get errors saying A cant find B. So I tried to predefine B like so:
  
class B;

class A
{
 public:

  double c;
  const void operator= (const B& b)
  {
    c = b.d;
  }
};

class B
{
 public:
  float d;
  const void operator= (const A& a)
  {
    d = (float)a.c;
  }
};

  
It didn''t work, I recived errors such as: use of undefined type ''B'' see declaration of ''B'' (which takes me to the first line of the snippet "class B;") I was sure that you could predefine classes this way, have I missed something? --------------------------
Those who dance are considered insane by those who cannot hear the music.

Share this post


Link to post
Share on other sites
Advertisement
That''s right. The ".d" is the problem. This would work:

  
class B;

class A
{
public:
double c;
const void operator= (const B& b);
};

class B
{
public:
float d;
const void operator= (const A& a);
};

const void A::operator= (const B& b)
{
c = b.d;
}

const void B::operator= (const A& a)
{
d = (float)a.c;
}


Share this post


Link to post
Share on other sites

  • Advertisement