This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ Language Lawyer Question
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: "Giovanni Bajo" <giovannibajo at libero dot it>
- Cc: "Joel Sherrill" <joel dot sherrill at OARcorp dot com>, <gcc at gcc dot gnu dot org>
- Date: 10 Feb 2004 21:03:34 +0100
- Subject: Re: C++ Language Lawyer Question
- Organization: Integrable Solutions
- References: <4029325C.7090004@OARcorp.com><205301c3f00e$1902d410$9cba2997@bagio>
"Giovanni Bajo" <giovannibajo@libero.it> writes:
| Joel Sherrill wrote:
|
| > namespace N {
| > class C {
| > private:
| > typedef int T1_t;
| > protected:
| > typedef int T2_t;
| > public:
| > C();
| > ~C();
| > int f1(T1_t); // private type used for public method
| > int f2(T2_t); // protected type used for public method
| > };
| > }
| >
| > N::C::C() { ; }
| > N::C::~C() { ; }
| > int N::C::f1(T1_t x) { return x+1; }
| > int N::C::f2(T2_t x) { return x+2; }
| >
| > Should this work? If so, what is the rationale for allowing it.
|
| Yes, there is nothing wrong with it. The fact that you can't directly name a
| C::T1_t doesn't make the member function useless. For instance, you could have
| a public member function in C which returns a T1_t (so that you can call it
| directly while calling f1()). Or you could call f1() with any other type for
| which there is a default conversion to T1_t.
Yes, you're even able to say
C().f1(90);
-- Gaby