473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

need for friend function

Stroustrup, in his book TC++PL 3rd Edition, in page 16, under the
section '1.8 Advice' has mentioned the following:
[2] [a] Don't use global data(use members)
[b] Don't use global functions
[c] Don't use public data members.
[d] Don't use friends, except to avoid [a] or [c].

Consider the following scenarios:

Scenario 1:
----------------
class Test
{
friend ostream & operator<<(ostream &os, const Test &ref);
}

Here the friend ostream &operator<<() can be avoided by providing a
Test::print_output() function and expect the user to explicitly call
Test_obj.print_output(os) for an object Test_obj of type Test.

Scenario 2:
----------------
class Test
{
friend Test operator+(const Test &arg1, const Test &arg2);
}

This friend function can be avoided as follows:

class Test
{
Test &operator+=(const Test &ref);
}

Test operator+(const Test &arg1, const &arg2)
{
Test temp(arg1);
return temp += arg2;
}

Scenario 3:
----------------
Consider invert(m) for inverting a 'Matrix m' to the alternative
m.invert()
By providing Matrix::invert(), here also the friend function can be
avoided.

I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.

Kindly explain.

Thanks
V.Subramanian
Dec 4 '07 #1
19 2685
su**************@yahoo.com wrote:
[..]
I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.
Here is the thing: absence of evidence is not evidence of absence.
If I've never encountered in my whole life any guidelines and/or
examples where using a friend function is unavoidable, it does not
mean there isn't any. However, consider this: if there are better
ways of doing something, and you have no reason for *not* using one
of the better ways, then the "not so good" mechanism is avoidable.
Invert that, and you get this: if there are compelling reasons not
to use any of the ways to avoid something, then this something
becomes unavoidable. If for some reason you cannot grant access
to some private data to everybody (declare the data public or
protected), *and* you cannot make certain function a member of the
class containing the private data, then you are stuck with making
the function a friend. I know, it's not concrete, but that's the
essence, AFA I'm concerned.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 4 '07 #2
On Dec 4, 3:56 pm, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Stroustrup, in his book TC++PL 3rd Edition, in page 16, under the
section '1.8 Advice' has mentioned the following:
[2] [a] Don't use global data(use members)
[b] Don't use global functions
[c] Don't use public data members.
[d] Don't use friends, except to avoid [a] or [c].

Consider the following scenarios:

Scenario 1:
----------------
class Test
{
friend ostream & operator<<(ostream &os, const Test &ref);

}

Here the friend ostream &operator<<() can be avoided by providing a
Test::print_output() function and expect the user to explicitly call
Test_obj.print_output(os) for an object Test_obj of type Test.

Scenario 2:
----------------
class Test
{
friend Test operator+(const Test &arg1, const Test &arg2);

}

This friend function can be avoided as follows:

class Test
{
Test &operator+=(const Test &ref);

}

Test operator+(const Test &arg1, const &arg2)
{
Test temp(arg1);
return temp += arg2;

}

Scenario 3:
----------------
Consider invert(m) for inverting a 'Matrix m' to the alternative
m.invert()
By providing Matrix::invert(), here also the friend function can be
avoided.

I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.

Kindly explain.

class A;
class B;
class C

C foo(A a,B b){
//I need to access private members of A,B and C.
//I must be a friend of at least two of them.
};

regards,
FM.

Dec 4 '07 #3
On Dec 4, 2:23 pm, terminator <farid.mehr...@gmail.comwrote:
On Dec 4, 3:56 pm, "subramanian10...@yahoo.com, India"

<subramanian10...@yahoo.comwrote:
Stroustrup, in his book TC++PL 3rd Edition, in page 16, under the
section '1.8 Advice' has mentioned the following:
[2] [a] Don't use global data(use members)
[b] Don't use global functions
[c] Don't use public data members.
[d] Don't use friends, except to avoid [a] or [c].
Consider the following scenarios:
Scenario 1:
----------------
class Test
{
friend ostream & operator<<(ostream &os, const Test &ref);
}
Here the friend ostream &operator<<() can be avoided by providing a
Test::print_output() function and expect the user to explicitly call
Test_obj.print_output(os) for an object Test_obj of type Test.
Scenario 2:
----------------
class Test
{
friend Test operator+(const Test &arg1, const Test &arg2);
}
This friend function can be avoided as follows:
class Test
{
Test &operator+=(const Test &ref);
}
Test operator+(const Test &arg1, const &arg2)
{
Test temp(arg1);
return temp += arg2;
}
Scenario 3:
----------------
Consider invert(m) for inverting a 'Matrix m' to the alternative
m.invert()
By providing Matrix::invert(), here also the friend function can be
avoided.
I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.
Kindly explain.

class A;
class B;
class C

C foo(A a,B b){
//I need to access private members of A,B and C.
//I must be a friend of at least two of them.

};

regards,
FM.
Most of the time you can use public methods instead...
Dec 4 '07 #4
On Dec 4, 8:23 am, terminator <farid.mehr...@gmail.comwrote:
On Dec 4, 3:56 pm, "subramanian10...@yahoo.com, India"

<subramanian10...@yahoo.comwrote:
Stroustrup, in his book TC++PL 3rd Edition, in page 16, under the
section '1.8 Advice' has mentioned the following:
[2] [a] Don't use global data(use members)
[b] Don't use global functions
[c] Don't use public data members.
[d] Don't use friends, except to avoid [a] or [c].
Consider the following scenarios:
Scenario 1:
----------------
class Test
{
friend ostream & operator<<(ostream &os, const Test &ref);
}
Here the friend ostream &operator<<() can be avoided by providing a
Test::print_output() function and expect the user to explicitly call
Test_obj.print_output(os) for an object Test_obj of type Test.
Scenario 2:
----------------
class Test
{
friend Test operator+(const Test &arg1, const Test &arg2);
}
This friend function can be avoided as follows:
class Test
{
Test &operator+=(const Test &ref);
}
Test operator+(const Test &arg1, const &arg2)
{
Test temp(arg1);
return temp += arg2;
}
Scenario 3:
----------------
Consider invert(m) for inverting a 'Matrix m' to the alternative
m.invert()
By providing Matrix::invert(), here also the friend function can be
avoided.
I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.
Kindly explain.

class A;
class B;
class C

C foo(A a,B b){
//I need to access private members of A,B and C.
//I must be a friend of at least two of them.

};

regards,
FM.
Sorry term, I think that is a very bad example. you may give the OP
the idea that any constructor with an argument will have to be a
friend of the argument type, which is quite false.

A and B should have public accessors, which the constructor of C can
use. If for some reason A and B cannot provide accessors, than that is
the reason for making them friends to C. However, the example does not
illustrate that unknown reason for A and B not having accessors.
Dec 4 '07 #5
On Dec 4, 8:09 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
subramanian10...@yahoo.com wrote:
[..]
I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.

Here is the thing: absence of evidence is not evidence of absence.
If I've never encountered in my whole life any guidelines and/or
examples where using a friend function is unavoidable, it does not
mean there isn't any. However, consider this: if there are better
ways of doing something, and you have no reason for *not* using one
of the better ways, then the "not so good" mechanism is avoidable.
Invert that, and you get this: if there are compelling reasons not
to use any of the ways to avoid something, then this something
becomes unavoidable. If for some reason you cannot grant access
to some private data to everybody (declare the data public or
protected), *and* you cannot make certain function a member of the
class containing the private data, then you are stuck with making
the function a friend. I know, it's not concrete, but that's the
essence, AFA I'm concerned.

My complaint about friendship is that its too coarse grained. I
almost never see the situation where one class actually needs to
access the private data members of another (and that's usually pretty
easy to design around, even if you just add some getters and
setters). What I have run into is the situation where two or more
classes need to share some interfaces within the group, but not with
classes outside that group.

While there are ways around that (notably making the semi-public
interfaces part of derived classes, although that brings other
problems, particularly the need to use a factory method), none of the
workarounds are all that clean (of course, neither is excessively
permissive friendship).
Dec 4 '07 #6
ro***********@yahoo.com wrote:
[..]
My complaint about friendship is that its too coarse grained. I
almost never see the situation where one class actually needs to
access the private data members of another (and that's usually pretty
easy to design around, even if you just add some getters and
setters). What I have run into is the situation where two or more
classes need to share some interfaces within the group, but not with
classes outside that group.

While there are ways around that (notably making the semi-public
interfaces part of derived classes, although that brings other
problems, particularly the need to use a factory method), none of the
workarounds are all that clean (of course, neither is excessively
permissive friendship).
To provide the functionality where only members of the group have
access to each other's privates ("family"? :-)) you can define
a "shared" class which will be the friend of them all and though
which they will request the access. Kind of like this:

class A {
int a;
friend class P;
public:
void foo();
};

class B {
int b;
friend class P;
public:
void foo();
};

class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};

void A::foo() {
B myb;
a = P::b(myb);
}

void B::foo() {
A mya;
b = P::a(mya);
}

int main() {
A a;
B b;
a.foo();
b.foo();
}

Note that 'A' is not a friend of 'B', nor 'B' is a friend of 'A'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 4 '07 #7
On Dec 4, 3:04 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
robertwess...@yahoo.com wrote:
[..]
My complaint about friendship is that its too coarse grained. I
almost never see the situation where one class actually needs to
access the private data members of another (and that's usually pretty
easy to design around, even if you just add some getters and
setters). What I have run into is the situation where two or more
classes need to share some interfaces within the group, but not with
classes outside that group.
While there are ways around that (notably making the semi-public
interfaces part of derived classes, although that brings other
problems, particularly the need to use a factory method), none of the
workarounds are all that clean (of course, neither is excessively
permissive friendship).

To provide the functionality where only members of the group have
access to each other's privates ("family"? :-)) you can define
a "shared" class which will be the friend of them all and though
which they will request the access. Kind of like this:

class A {
int a;
friend class P;
public:
void foo();
};

class B {
int b;
friend class P;
public:
void foo();
};

class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};

void A::foo() {
B myb;
a = P::b(myb);
}

void B::foo() {
A mya;
b = P::a(mya);
}

int main() {
A a;
B b;
a.foo();
b.foo();
}

Note that 'A' is not a friend of 'B', nor 'B' is a friend of 'A'.

Yes, I've seen that pattern (more precisely with accessor classes for
each class in the family, rather than one big one for the whole
family), but it's far from pretty. At least with the derived class
approach you can call the functions with the normal type resolution
and syntax, although it's difficult to extend that to multiple
families (although that's only been an issue on a couple of occasions).
Dec 4 '07 #8
On Dec 5, 2:04 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
robertwess...@yahoo.com wrote:
[..]
My complaint about friendship is that its too coarse grained. I
almost never see the situation where one class actually needs to
access the private data members of another (and that's usually pretty
easy to design around, even if you just add some getters and
setters). What I have run into is the situation where two or more
classes need to share some interfaces within the group, but not with
classes outside that group.
While there are ways around that (notably making the semi-public
interfaces part of derived classes, although that brings other
problems, particularly the need to use a factory method), none of the
workarounds are all that clean (of course, neither is excessively
permissive friendship).

To provide the functionality where only members of the group have
access to each other's privates ("family"? :-)) you can define
a "shared" class which will be the friend of them all and though
which they will request the access. Kind of like this:

class A {
int a;
friend class P;
public:
void foo();
};

class B {
int b;
friend class P;
public:
void foo();
};

class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};
static functions accessing non-static member variables?
void A::foo() {
B myb;
a = P::b(myb);
}

void B::foo() {
A mya;
b = P::a(mya);
}

int main() {
A a;
B b;
a.foo();
b.foo();
}

Note that 'A' is not a friend of 'B', nor 'B' is a friend of 'A'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 5 '07 #9
On Dec 5, 8:18 am, Rahul <sam_...@yahoo.co.inwrote:
On Dec 5, 2:04 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
To provide the functionality where only members of the group have
access to each other's privates ("family"? :-)) you can define
a "shared" class which will be the friend of them all and though
which they will request the access. Kind of like this:
class A {
int a;
friend class P;
public:
void foo();
};
class B {
int b;
friend class P;
public:
void foo();
};
class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};

static functions accessing non-static member variables?
Would that be a problem? Note that the static functions belong to
class P and the non-static members are of classes A and B.
Dec 5 '07 #10
>
class A {
int a;
friend class P;
public:
void foo();
};

class B {
int b;
friend class P;
public:
void foo();
};

class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};

void A::foo() {
B myb;
a = P::b(myb);
}

void B::foo() {
A mya;
b = P::a(mya);
}

int main() {
A a;
B b;
a.foo();
b.foo();
}

Note that 'A' is not a friend of 'B', nor 'B' is a friend of 'A'.
that is a one ugly pattern...
I'm not sure you should use this one...

Why strousrup is advising not to use friends?
Dec 5 '07 #11
ManicQin wrote:
[..]
Why strousrup is advising not to use friends?
^^^^^^^^^
I am not sure who (or what) that is.

Friendship goes against the data/implementation hiding principle.
If you make something private, that's really only for you to see.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 5 '07 #12
On Dec 4, 10:48 pm, Christopher <cp...@austin.rr.comwrote:
On Dec 4, 8:23 am, terminator <farid.mehr...@gmail.comwrote:


On Dec 4, 3:56 pm, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Stroustrup, in his book TC++PL 3rd Edition, in page 16, under the
section '1.8 Advice' has mentioned the following:
[2] [a] Don't use global data(use members)
[b] Don't use global functions
[c] Don't use public data members.
[d] Don't use friends, except to avoid [a] or [c].
Consider the following scenarios:
Scenario 1:
----------------
class Test
{
friend ostream & operator<<(ostream &os, const Test &ref);
}
Here the friend ostream &operator<<() can be avoided by providing a
Test::print_output() function and expect the user to explicitly call
Test_obj.print_output(os) for an object Test_obj of type Test.
Scenario 2:
----------------
class Test
{
friend Test operator+(const Test &arg1, const Test &arg2);
}
This friend function can be avoided as follows:
class Test
{
Test &operator+=(const Test &ref);
}
Test operator+(const Test &arg1, const &arg2)
{
Test temp(arg1);
return temp += arg2;
}
Scenario 3:
----------------
Consider invert(m) for inverting a 'Matrix m' to the alternative
m.invert()
By providing Matrix::invert(), here also the friend function can be
avoided.
I want to know if there are some guidelines and examples where the
need for using a friend function is unavoidable.
Kindly explain.
class A;
class B;
class C
C foo(A a,B b){
//I need to access private members of A,B and C.
//I must be a friend of at least two of them.
};
regards,
FM.

Sorry term, I think that is a very bad example. you may give the OP
the idea that any constructor with an argument will have to be a
friend of the argument type, which is quite false.
I did not mean that every function needs public access to its
operands/return.
A and B should have public accessors, which the constructor of C can
use. If for some reason A and B cannot provide accessors, than that is
the reason for making them friends to C. However, the example does not
illustrate that unknown reason for A and B not having accessors.
not always possible if public interface A,B and C is interelated , you
can not avoid friend declarations.

regards,
FM.

Dec 5 '07 #13
On Dec 5, 8:53 am, Abhishek Padmanabh <abhishek.padman...@gmail.com>
wrote:
On Dec 5, 8:18 am, Rahul <sam_...@yahoo.co.inwrote:


On Dec 5, 2:04 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
To provide the functionality where only members of the group have
access to each other's privates ("family"? :-)) you can define
a "shared" class which will be the friend of them all and though
which they will request the access. Kind of like this:
class A {
int a;
friend class P;
public:
void foo();
};
class B {
int b;
friend class P;
public:
void foo();
};
class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};
static functions accessing non-static member variables?

Would that be a problem? Note that the static functions belong to
class P and the non-static members are of classes A and B.
that does not change any thing;but you are right in that the only
difference between none static and static members is that the former
do not get a hidden 'this' parameter.

regards,
FM.
Dec 5 '07 #14
On Dec 5, 5:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
ManicQin wrote:
[..]
Why strousrup is advising not to use friends?

^^^^^^^^^
I am not sure who (or what) that is.

Friendship goes against the data/implementation hiding principle.
If you make something private, that's really only for you to see.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
some languages(certainly not C++) indroduce some 'internal' access
specifier that bounds access to the same module;something like what
'static' declaration of functions does in C.

regards,
FM.
Dec 5 '07 #15
On Dec 5, 10:34 pm, terminator <farid.mehr...@gmail.comwrote:
On Dec 5, 8:53 am, Abhishek Padmanabh <abhishek.padman...@gmail.com>
wrote:
On Dec 5, 8:18 am, Rahul <sam_...@yahoo.co.inwrote:
On Dec 5, 2:04 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
To provide the functionality where only members of the group have
access to each other's privates ("family"? :-)) you can define
a "shared" class which will be the friend of them all and though
which they will request the access. Kind of like this:
class A {
int a;
friend class P;
public:
void foo();
};
class B {
int b;
friend class P;
public:
void foo();
};
class P { // everything is private
friend class A;
friend class B;
static int &a(A& ai) { return ai.a; }
static int &b(B& bi) { return bi.b; }
};
static functions accessing non-static member variables?
Would that be a problem? Note that the static functions belong to
class P and the non-static members are of classes A and B.

that does not change any thing;but you are right in that the only
difference between none static and static members is that the former
do not get a hidden 'this' parameter.
I don't know what you tried to mean here but there is no relation to
the 'this' pointer in the above example's case. I did not say anything
related to static and non-static members and the this pointer
associated with the non-static member functions. That fact does not
form the basis of why the code above works. The static functions in P
just need an object of type A and B to access their private members.
Dec 5 '07 #16
On Dec 5, 3:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
ManicQin wrote:
[..]
Why strousrup is advising not to use friends?
^^^^^^^^^
I am not sure who (or what) that is.
A misspelling of Stroustrup?
Friendship goes against the data/implementation hiding
principle. If you make something private, that's really only
for you to see.
I don't think that Stroustrup advises unconditionally against
friends. If he had felt that there was never a reason to use a
friend, he wouldn't have added the concept to the language.

The important thing, I think, is to consider friends as part of
the interface of your class. Don't (normally) make anything a
friend that isn't implemented as part of your class
implementation. Used correctly, friends increase encapsulation
and hiding.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 6 '07 #17
On Dec 6, 1:49 pm, James Kanze <james.ka...@gmail.comwrote:
On Dec 5, 3:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
ManicQin wrote:
[..]
Why strousrup is advising not to use friends?
^^^^^^^^^
I am not sure who (or what) that is.

A misspelling of Stroustrup?
Friendship goes against the data/implementation hiding
principle. If you make something private, that's really only
for you to see.

I don't think that Stroustrup advises unconditionally against
friends. If he had felt that there was never a reason to use a
friend, he wouldn't have added the concept to the language.

The important thing, I think, is to consider friends as part of
the interface of your class. Don't (normally) make anything a
friend that isn't implemented as part of your class
implementation. Used correctly, friends increase encapsulation
and hiding.

first thing, victor! a strousrup is another name for Cthulhu.;)
second, It's true that "Friendship goes against the data/
implementation hiding" but I think that two classes which are bound
with a friend relationship could be looked as an inclosed interface.
Dec 10 '07 #18
ManicQin wrote:
On Dec 6, 1:49 pm, James Kanze <james.ka...@gmail.comwrote:
>On Dec 5, 3:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>>ManicQin wrote:
[..]
Why strousrup is advising not to use friends?
^^^^^^^^^
I am not sure who (or what) that is.

A misspelling of Stroustrup?
>>Friendship goes against the data/implementation hiding
principle. If you make something private, that's really only
for you to see.

I don't think that Stroustrup advises unconditionally against
friends. If he had felt that there was never a reason to use a
friend, he wouldn't have added the concept to the language.

The important thing, I think, is to consider friends as part of
the interface of your class. Don't (normally) make anything a
friend that isn't implemented as part of your class
implementation. Used correctly, friends increase encapsulation
and hiding.


first thing, victor! a strousrup is another name for Cthulhu.;)
second, It's true that "Friendship goes against the data/
implementation hiding" but I think that two classes which are bound
with a friend relationship could be looked as an inclosed interface.
Well, manicqin, you need to elaborate. An "enclosed" (did you mean
'enclosed'? I am hoping you did) interface: enclosed by what, or
enclosed where, or enclosed with what? Also, remember that frienship
is non-symmetrical (while parts of interfaces are, usually).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 10 '07 #19
On Dec 10, 5:13 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
ManicQin wrote:
On Dec 6, 1:49 pm, James Kanze <james.ka...@gmail.comwrote:
On Dec 5, 3:26 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>ManicQin wrote:
[..]
Why strousrup is advising not to use friends?
^^^^^^^^^
I am not sure who (or what) that is.
A misspelling of Stroustrup?
>Friendship goes against the data/implementation hiding
principle. If you make something private, that's really only
for you to see.
I don't think that Stroustrup advises unconditionally against
friends. If he had felt that there was never a reason to use a
friend, he wouldn't have added the concept to the language.
The important thing, I think, is to consider friends as part of
the interface of your class. Don't (normally) make anything a
friend that isn't implemented as part of your class
implementation. Used correctly, friends increase encapsulation
and hiding.
first thing, victor! a strousrup is another name for Cthulhu.;)
second, It's true that "Friendship goes against the data/
implementation hiding" but I think that two classes which are bound
with a friend relationship could be looked as an inclosed interface.

Well, manicqin, you need to elaborate. An "enclosed" (did you mean
'enclosed'? I am hoping you did) interface: enclosed by what, or
enclosed where, or enclosed with what? Also, remember that frienship
is non-symmetrical (while parts of interfaces are, usually).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I meant inclosed... my dictionary (babylon) says the "enclosed" and
"inclosed" are the same
(maybe its like color and colour...) but maybe, just maybe it was'nt
the right word to use.

ok what I meant is (IMHO) that the concept of interface is not applied
only to the in/out operations of a single class, a set of classes
could form an interface too.
(ctrl+c ctrl+v) Friendship goes against the data/implementation hiding
of a class but not of a complete interface.
of course you could misuse the interface and "hack" your way in to a
class threw the friendship but the same could be told about
protected...

p.s. please forgive me for my summarized definition of an interface.
Dec 11 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. ...
2
by: Christophe Barbe | last post by:
I posted a few days ago about the same problem but was not very clear. So here is my second take at it. Basically with GCC 3.3.2, I can't compile the example from the C++ FAQ Lite available...
10
by: Piotr Wyderski | last post by:
Hello, is it possible to reuse a friend operator which is defined inside a class? I'd like to obtain the following behaviour: class integer { integer operator +(signed long int v) const...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
1
by: gw7rib | last post by:
Suppose I have a function, whose protoype is somewhat complicated, for example, with some #defines and typedefs, it looks like this: INT_PTR CALLBACK PropDlgProc(HWND hDlg, UINT message, WPARAM...
3
by: Terry Olsen | last post by:
I'm trying to add a domain user to a local group using the code below: Dim LCL As New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer") Dim DOM As New...
15
by: active | last post by:
Below is a small but complete program that appears to show you can't retrive a Palette from the clipboard. This is true whether the palette is placed on the clipboard by Photoshop or Photoshop...
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
9
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.