[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Template function calling a templated function in the templated class
From: |
Charles Karney |
Subject: |
Template function calling a templated function in the templated class |
Date: |
Mon, 09 Oct 2006 11:26:03 -0400 |
User-agent: |
Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) |
Configuration:
g++ (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8)
Fedora Core 4, 2.6.16, i686
Consider the following code
#include <iostream>
#include <limits>
class foo {
public:
template<class S> int foof0()
{ return std::numeric_limits<S>::digits; }
template<class S> int foof1(S a)
{ return std::numeric_limits<S>::digits; }
};
class bar {
public:
template<class X> int barf(X x) { return x.foof0<double>(); }
// template<class X> int barf(X x) { return x.foof1(1.0); }
};
int main() {
foo a;
bar b;
std::cout << b.barf(a) << std::endl;
}
bar::barf is templated on the type of its argument and, with an argument
of type foo, is supposed to call foo::foof0<double>(). Compiling this
with g++ gives:
g++ test.cpp -o test
test.cpp: In member function 'int bar::barf(X)':
test.cpp:14: error: expected primary-expression before 'double'
test.cpp:14: error: expected ';' before 'double'
test.cpp:14: error: expected unqualified-id before '>' token
Notes:
(1) Replacing the definition of bar::barf by the commented version makes
the bug go away (the program prints out 53).
(2) The problem evidently isn't with the instantiation of bar::barf. I
get precisely the same error with an empty main program.
(3) Visual C++ 7.0 compiles this without complaint, so I don't think I'm
misusing C++.
Thanks for your attention...
--
Charles Karney <address@hidden>
Sarnoff Corporation, Princeton, NJ 08543-5300
URL: http://charles.karney.info
Tel: +1 609 734 2312
Fax: +1 609 734 2662
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Template function calling a templated function in the templated class,
Charles Karney <=