By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,851 Members | 2,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,851 IT Pros & Developers. It's quick & easy.

problem in static function template specialization

P: n/a
The following code reproduces a problem I'm having with the GCC compiler. It
compiles fine on MSVC, so I'm wondering whether it is legal C++ code or not.

template<typename C>
struct Provider
{
template<typename T>
static void func() {}
};

template<typename C, typename Pro>
struct Client
{
void create()
{
Pro::func<C>(); // compiler stops here
}
};

int main()
{
Client<int, Provider<double> > cli;
cli.create();
return 0;
}
The GNU compiler gives me a "parse error" at this line:

Pro::func<C>();

Note that if parameter T in Provider::func() was deducible automatically
(for example through a function argument), the code would compile. It seems
that the explicit template specialization above confuses the compiler.

Am I doing something wrong?

Cheers,
Marco
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Marco Jez schrieb:
The following code reproduces a problem I'm having with the GCC compiler. It
compiles fine on MSVC, so I'm wondering whether it is legal C++ code or not.

template<typename C>
struct Provider
{
template<typename T>
static void func() {}
};

template<typename C, typename Pro>
struct Client
{
void create()
{
Pro::func<C>(); // compiler stops here Pro::template func<C>(); // correct }
};

int main()
{
Client<int, Provider<double> > cli;
cli.create();
return 0;
}
The GNU compiler gives me a "parse error" at this line:

Pro::func<C>();

Note that if parameter T in Provider::func() was deducible automatically
(for example through a function argument), the code would compile. It seems
that the explicit template specialization above confuses the compiler.

Am I doing something wrong?


See above. Similarly to the required use of typename with dependent
types (see the recent "trying to declare an iterator for a std::vector
of template pointers" thread), you have to explicitly tell the compiler
that Pro::foo is a template function here.

HTH,
Malte
Jul 23 '05 #2

P: n/a
Marco Jez wrote:
The following code reproduces a problem I'm having with the GCC
compiler. It compiles fine on MSVC, so I'm wondering whether it is
legal C++ code or not.
template<typename C>
struct Provider
{
template<typename T>
static void func() {}
};

template<typename C, typename Pro>
struct Client
{
void create()
{
Pro::func<C>(); // compiler stops here
I think you need

Pro::template func<C>();

here.

}
};

int main()
{
Client<int, Provider<double> > cli;
cli.create();
return 0;
}
The GNU compiler gives me a "parse error" at this line:

Pro::func<C>();

Note that if parameter T in Provider::func() was deducible
automatically (for example through a function argument), the code
would compile. It seems that the explicit template specialization
above confuses the compiler.
Am I doing something wrong?


Missing the 'template' keyword. See above.

V
Jul 23 '05 #3

P: n/a
> I think you need

Pro::template func<C>();

here.


Thanks Victor and Malte. I must admit I've never seen this syntax before...
:-)

Cheers,
Marco
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.