Thread View: comp.std.c++
3 messages
3 total messages
Started by dak
Mon, 25 Mar 1996 18:09
double const declarations
Author: dak
Date: Mon, 25 Mar 1996 18:09
Date: Mon, 25 Mar 1996 18:09
25 lines
1544 bytes
1544 bytes
I've just encountered a problem in one of our template design and wondered
what could be done about it. It concerns const reference return value from
a templated member function, for example:
template <class T> class SmartPtr
{
// ... whatever:
public:
const T & Dereference ();
};
The problem arise when T is instantiated with a Container of constants:
SmartPtr<const int> a;
Here we have a double const which is not supported by the compiler, nor the
standard, I believe. Is there a fix or should we abandon all hope of using
const returns in templates ?
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Re: double const declarations
Author: James Kanze US/ESC 60/3/141 #407...
Date: Tue, 26 Mar 1996 16:23
Date: Tue, 26 Mar 1996 16:23
40 lines
2273 bytes
2273 bytes
In article <Pine.A32.3.91.960325093715.29874A-100000@zorglub.cae.ca>
dak <pierreba@poster.cae.ca> writes:
|> I've just encountered a problem in one of our template design and wondered
|> what could be done about it. It concerns const reference return value from
|> a templated member function, for example:
|> template <class T> class SmartPtr
|> {
|> // ... whatever:
|> public:
|> const T & Dereference ();
|> };
|> The problem arise when T is instantiated with a Container of constants:
|> SmartPtr<const int> a;
|> Here we have a double const which is not supported by the compiler, nor the
|> standard, I believe. Is there a fix or should we abandon all hope of using
|> const returns in templates ?
The draft standard forbids two explicit const's. If the duplicate
Const result from typedef's, etc., it's OK. (I don't know if the
actual words mention template instantiation types, but if they don't
I'm sure that it is an editorial oversight, and not the intent.)
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
-- A la recherche d'une activité dans une region francophone
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: double const declarations
Author: David Byrden
Date: Thu, 28 Mar 1996 21:16
Date: Thu, 28 Mar 1996 21:16
24 lines
1597 bytes
1597 bytes
dak <pierreba@poster.cae.ca> wrote:
>The problem arise when T is instantiated with a Container of constants:
>
>SmartPtr<const int> a;
>
>Here we have a double const which is not supported by the compiler, nor the
>standard, I believe. Is there a fix or should we abandon all hope of using
>const returns in templates ?
Sheer common sense tell you that we have to allow this. It can arise
with 'volatile' as well. The Microsoft compiler gives just a warning.
David
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads