Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:15:40+00:00 2026-06-02T22:15:40+00:00

Duplicate question of this . I have a class like this: template <class T>

  • 0

Duplicate question of this.

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 the 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 as the BOOST_AUTO_TEST_CASE_TEMPLATE is doing something weird…

Following text is deprecated:

However, when I call the function with:

foo f;
f.bar<1>();

I am getting the error:

A bound member function may only be called

If I however wrap the bar function into something like void bar1(){return bar<1>();}, it would work. I know if T is not known during compile time, it will not compile. But I don’t know why the compiler is not smart enough to figure out the 1 in f.bar<1> is static?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:15:41+00:00Added an answer on June 2, 2026 at 10:15 pm

    Because the T argument is unknown when parsing the test function, the compiler is unable to determine what the m.bar expression is, and therefore assumes it is a non-template variable. m.bar<1>() is therfore parsed as (m.bar<1)>(), the last bit being illegal. The fix is to explictly state that bar is a template:

    foo<T> m;
    m.template bar<1>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: optimal algorithm for finding unique divisors I have asked this question before,
Quick question... I have a query that checks for duplicates that looks like this:
Possible Duplicate: class << self idiom in Ruby I have a quick Ruby question.
I have something like the following in the header class MsgBase { public: unsigned
This question pertains primarily to good design. Suppose I have a controller action like
Possible Duplicate: jQuery attribute selector for multiple values I have this $('input:radio[name=foo]').change(function() { blah();
I may be going about this backwards... I have a class which is like
This might be a duplicate question as I have found a few that are
This question is a duplicate of this question by intention. It seems like the
I have a question about templates. I would like to have a templated class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.