Thread View: comp.std.c++
1 messages
1 total messages
Started by Wil Evers
Wed, 30 Aug 1995 08:25
Re: Template instantiation question
Author: Wil Evers
Date: Wed, 30 Aug 1995 08:25
Date: Wed, 30 Aug 1995 08:25
47 lines
2057 bytes
2057 bytes
In article <41vlmh$kat@engnews2.Eng.Sun.COM>, stephen.clamage@Eng.sun.com (Steve
Clamage) wrote:
> In article i3d@engnews2.Eng.Sun.COM, "bnr (n.) postmaster" <postmast@bnr.ca>
writes:
[snip]
> >
> >template<class T>
> >class MyPtrClass {
> > T* ptr;
> >public:
> > // etc...
> > T* operator->(void) { return(ptr); }
> > // etc...
> >};
> >
> >
> >This causes problems on some compilers (e.g. Borland C++ v4.5) if type
> >'T' is does not have "operator->" defined, even if I never call the
> >"operator->" defined above.
>
> I believe the template declaration is valid only when T is a class type.
> Section 13.5.6 "Class Member Access" places requirements on the return type
> of operator->. When the class template is processed, the declaration would be
> invalid even if you never use the function.
>
> Possibly someone could point out something in the draft which makes the
> template valid as long is operator-> is never actually referenced.
Does anyone know why the restriction 'operator->() must return a class type' was
included in the standard, even when its result is never used to access a class
member? After all, this rule makes it impossible to write a smart pointer
template pointing to a type T that works both when T is a class type and when T
is something else.
If there is no clear rationale for this restriction, I think it should be
dropped.
[I think it *has* been dropped. -fjh (moderator).]
- Wil Evers (wil@ittpub.nl)
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
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