friends heredity

A

ahso

Hi
i want in class CK89gps declare a new instance of CK89gauge which is a
friend:

class CK89gps : public CDependent {
friend class CK89gauge;
......
protected:
CK89gauge *Gauge; // How should this line look??

Many thanks
Michael Sgier
 
R

Richard Herring

In message
Hi
i want in class CK89gps declare a new instance of CK89gauge which is a
friend:

You can't. Functions and classes can be friends, but not particular
instances of a class.
class CK89gps : public CDependent {
friend class CK89gauge;
.....
protected:
CK89gauge *Gauge; // How should this line look??
By definition, all instances of CK89gauge have the same behaviour.
How could the compiler possibly generate code in its member functions
that would allow one specific instance of it to access CK89gps, but no
others?
 
S

Saeed Amrollahi

Hi
i want in class CK89gps declare a new instance of CK89gauge which is a
friend:

class CK89gps : public CDependent {
  friend class CK89gauge;
.....
protected:
  CK89gauge        *Gauge;   // How should this line look??

Many thanks
Michael Sgier

Hi Michael

They are two independent concepts: friend declaration and class data
member
declaration. by
friend class CK89guage;
you mean an object of CK89guage can access to private and protected
members of
a CK89gps object. By
CK89guage *Gauge;
you declare a pointer data member.
I guess you need to one of them.

Regards,
-- Saeed Amrollahi
 
V

Vladimir Jovic

Richard said:
In message


You can't. Functions and classes can be friends, but not particular
instances of a class.

By definition, all instances of CK89gauge have the same behaviour.
How could the compiler possibly generate code in its member functions
that would allow one specific instance of it to access CK89gps, but no
others?

I find the OP's question very confusing, but your answer is even more
confusing.
His "example" doesn't contain templates, therefore he might want to ask
something different then what you answered.
 
R

Richard Herring

Vladimir Jovic said:
I find the OP's question very confusing, but your answer is even more
confusing.
His "example" doesn't contain templates, therefore he might want to ask
something different then what you answered.

I find your response more confusing still. Where did I mention
templates, or anything to do with templates?
 
V

Vladimir Jovic

Richard said:
I find your response more confusing still. Where did I mention
templates, or anything to do with templates?

Right. Nowhere. As I said, I was confused, and haven't understood the
question in the first place ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top