Duplicate question.
I have a class like this:
template <class T>
class foo {
public:
foo(){}
template <int S>
void bar (){}
}
If this class is called with:
int main(){
foo<float> m;
m.bar<1>();
}
It gives an error:
error: expected primary expression before ')' token
deprecated again:
My code is:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/mpl/list.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_case_template.hpp>
using namespace boost::unit_test;
#include "foo.hpp"
BOOST_AUTO_TEST_SUITE();
typedef boost::mpl::list<char, int> test_types;
BOOST_AUTO_TEST_CASE_TEMPLATE(test_Mat_constructor_hwd, T, test_types){
foo<T> m;
m.bar<1>();
}
BOOST_AUTO_TEST_SUITE_END()
This, however, does not compile, since BOOST_AUTO_TEST_CASE_TEMPLATE does something strange ...
The following text is deprecated:
However, when I call the function with:
foo f;
f.bar<1>();
I get an error message:
A related member function can only be called
If I, however, wrap the bar function in something like void bar1 () {return bar <1> ();}, this will work. I know if T is not known at compile time, it will not compile. But I do not know why the compiler is not smart enough to understand that 1 in f.bar <1> is static?
thank!