Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #71210
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: explicit specialization problem |
| Date | 2020-01-07 23:23 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <qv30ce$5tr$1@dont-email.me> (permalink) |
| References | <qv1mcf$vi4$1@news.albasani.net> |
On 07.01.2020 11:26, Bonita Montero wrote:
> Why does this work with an older g++ (6.3.0) and not with MSVC:
>
> #include <iostream>
>
> using namespace std;
>
> template<typename T>
> struct My
> {
> };
>
> template<typename T>
> struct Lib
> {
> void f();
> };
>
> template<typename T>
> void Lib<T>::f()
> {
> cout << "void Lib<T>::f()" << endl;
> }
>
> template<>
> template<typename T>
> struct Lib<My<T>>
> {
> void f();
> };
The `template<>` does not make sense here.
Just remove that line.
> template<typename T>
> void Lib<My<T>>::f()
> {
> cout << "void Lib<My<T>>::f()" << endl;
> }
>
> int main()
> {
> Lib<My<int>> lmi;
> lmi.f();
> }
>
> MSVC:
> x.cpp(22): error C2910: 'Lib<My<T>>': cannot be explicitly specialized
> x.cpp(31): error C2039: 'f': is not a member of 'Lib<My<T>>'
> x.cpp(30): note: see declaration of 'Lib<My<T>>'
> x.cpp(31): error C2447: '{': missing function header (old-style formal
> list?)
I get the same diagnostics with MSVC 2019.
With MinGW g++ 9.2:
_.cpp:25:8: error: too many template-parameter-lists
25 | struct Lib<My<T>>
| ^~~~~~~~~~
_.cpp:31:20: error: invalid use of incomplete type 'struct Lib<My<T> >'
31 | void Lib<My<T>>::f()
| ^
_.cpp:12:8: note: declaration of 'struct Lib<My<T> >'
12 | struct Lib
| ^~~
When the offending `template<>` is removed both compilers accept the code.
- Alf
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-07 11:26 +0100
Re: explicit specialization problem Ian Collins <ian-news@hotmail.com> - 2020-01-08 10:26 +1300
Re: explicit specialization problem "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-01-07 23:23 +0100
Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 07:29 +0100
Re: explicit specialization problem "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-07 22:34 -0800
Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 07:46 +0100
Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-07 22:58 -0800
Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 10:36 +0100
Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 03:56 -0800
Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 13:00 +0100
Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 06:02 -0800
Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 15:15 +0100
Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 06:48 -0800
Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 15:53 +0100
Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 07:16 -0800
Re: explicit specialization problem Manfred <noname@add.invalid> - 2020-01-08 16:28 +0100
Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-08 15:00 +0000
Re: explicit specialization problem "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-08 14:44 -0800
Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-09 02:20 +0000
Re: explicit specialization problem "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-08 19:42 -0800
Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-09 18:17 +0000
Re: explicit specialization problem Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-09 19:40 +0000
Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-09 21:21 +0000
csiph-web