Thread View: comp.std.c++
2 messages
2 total messages
Started by John E. Potter
Sun, 17 Mar 1996 03:59
Template instantiation
Author: John E. Potter
Date: Sun, 17 Mar 1996 03:59
Date: Sun, 17 Mar 1996 03:59
40 lines
1888 bytes
1888 bytes
I have only found one compiler which accepts the following. The others
attempt to instantiate class N prior to completing class L. As I read
DWP-14.3 [temp.inst], class N<int> should not be instantiated in the
following code. It would be instantiated when some class L<int> function
used an N<int>.
template <class T> class N;
template <class T> class L {
public :
// ...
private :
N<T>* ptr;
};
template <class T> class N {
private :
N (T, const L<T>&);
L<T> next; // error L<int> incomplete type, size unknown
T data;
friend class L<T>;
};
int main () {
L<int> l;
}
Do I have one correct compiler that accepts it, several correct compilers
which reject it, or (I hope not) all correct compilers because it is not
specified?
If the latter, is there any standard way to make this portable. I can
change ptr to a void* and reinterpret_castrate everything, but that is
not very pleasing.
Thanks,
John
---
[ 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: Template instantiation
Author: Nathan Myers, http://www.cantrip...
Date: Thu, 21 Mar 1996 02:48
Date: Thu, 21 Mar 1996 02:48
35 lines
2224 bytes
2224 bytes
John E. Potter wrote:
>
> I have only found one compiler which accepts the following. The others
> attempt to instantiate class N prior to completing class L. As I read
> DWP-14.3 [temp.inst], class N<int> should not be instantiated in the
> following code. It would be instantiated when some class L<int> function
> used an N<int>.
>
> template <class T> class N;
> template <class T> class L { N<T>* ptr; };
> template <class T> class N { L<T> next; };
> int main () { L<int> l; }
>
> Do I have one correct compiler that accepts it, several correct compilers
> which reject it, or (I hope not) all correct compilers because it is not
> specified?
You have one (at least semi-) correct compiler, and several broken ones.
> If the latter, is there any standard way to make this portable? I can
> change ptr to a void* and reinterpret_castrate everything, but that is
> not very pleasing.
You could change the member to a void* and provide an (inline) access
function that does the cast, in only one place. Better to use
non-broken compilers, of course.
Nathan Myers
ncm@cantrip.org http://www.cantrip.org/
---
[ 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