A
Aman
does it matter if a typedef is declared under public or private ?
does any one (public or private ) constitute better design ?
does any one (public or private ) constitute better design ?
Aman said:does it matter if a typedef is declared under public or private ?
does any one (public or private ) constitute better design ?
Aman said:The following piece of code works just fine .
even though typedef int T has been declared private , easily used in
main.
(I am assuming it's because the name T is visible in main too -
correct ?)
Does it make a difference (in terms of good design ) if I make it
private or public ?
#include <iostream>
class A {
private :
typedef int T;
} ;
int main(){
A::T i ;
i = 17 ;
cout << i << endl ;
}
Compiler bug? What compiler (brand/version) are you using?Aman said:The following piece of code works just fine.
even though typedef int T has been declared private,
easily used in main.
(I am assuming it's because the name T is visible
in main too - correct?)
This compiles neither with gcc 3.3.1 nor with#include <iostream>
class A {
private :
typedef int T;
} ;
int main(){
A::T i ;
i = 17 ;
cout << i << endl ;
}
In message said:The following piece of code works just fine .
even though typedef int T has been declared private , easily used in
main.
(I am assuming it's because the name T is visible in main too - correct
?)
Does it make a difference (in terms of good design ) if I make it
private or public ?
<snip>Aman said:hmm... that's interesting .
I am using g++ 2.95.2 on SunOS 5.8.
The reason I asked was because I was tinkering with the difference
between visibility and accessibility .
got from Herb sutter article in cuj- (Mostly)private .
"A private member is visible to all code that sees the class's
definition. This means that ... it participates in name lookup and
overload resolution and so can make calls invalid or ambiguous
even though it itself could never be called."
after which I was wondering that it might be that the typedef holds
good for the rest of main() because the class is visible .
would that be correct ? or is it still "bad compiler" explanation.
I'm kinda confused now.
Aman Angrish said:hmm... that's interesting .
I am using g++ 2.95.2 on SunOS 5.8.
The reason I asked was because I was tinkering with the difference
between visibility and accessibility .
got from Herb sutter article in cuj- (Mostly)private .
"A private member is visible to all code that sees the class's
definition. This means that ... it participates in name lookup and
overload resolution and so can make calls invalid or ambiguous
even though it itself could never be called."
after which I was wondering that it might be that the typedef holds
good for the rest of main() because the class is visible .
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.