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 8111883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:17:18+00:00 2026-06-06T02:17:18+00:00

I was attempting to make some expression templates as an answer to this question

  • 0

I was attempting to make some expression templates as an answer to this question, but I’m getting compiler errors, that I can’t figure out. I have gotten the SSCCE quite small by now

template<class sub_expr>
class inherit2 : private sub_expr { //line 3
public:
    inherit2(sub_expr rhs) : sub_expr(rhs) {}
    template<class T>
    auto operator()(const T& v) const ->decltype(sub_expr::operator()(v)) //line 7
    {return sub_expr::operator()(v);}
};

class expression_parameter {
public:
    template<class T>
    const T& operator()(const T& v) const {return v;}
};

int main() {
    expression_parameter x;
    auto expr0 = x;
    int res0 = expr0(3); //line 20
    auto expr1 = inherit2<expression_parameter>(x); //line 21
    int res1 = expr1(3); //line 22
    return 0;
}

When I compile with MSVC10++ I get this error:

f:\code\utilities\exprtemplate\exprtemplate\sscce.cpp(22): error C2893: Failed to specialize function template ''unknown-type' inherit2<sub_expr>::operator ()(const T &) const'
with
[
    sub_expr=expression_parameter
]
With the following template arguments:
'int'

When I compile with GCC 4.6.3:

sscce.cpp: In instantiation of 'inherit2<expression_parameter>':
sscce.cpp:21:47:   instantiated from here
sscce.cpp:3:7: warning: base class 'class expression_parameter' has a non-virtual destructor [-Weffc++]
sscce.cpp: In function 'int main()':
sscce.cpp:22:20: error: no match for call to '(inherit2<expression_parameter>) (int)'
sscce.cpp:3:7: note: candidate is:
sscce.cpp:7:10: note: template<class T> decltype (sub_expr:: operator()(v)) inherit2::operator()(const T&) const [with T = T, sub_expr = expression_parameter, decltype (sub_expr:: operator()(v)) = decltype (expression_parameter::operator()(v))]
sscce.cpp:20:6: warning: unused variable 'res0' [-Wunused-variable]
sscce.cpp:22:6: warning: unused variable 'res1' [-Wunused-variable]

And finally Clang 3.1

sscce.cpp(22,12) :  error: no matching function for call to object of type 'inherit2<expression_parameter>'
        int res1 = expr1(3);
                   ^~~~~
sscce.cpp(7,9) :  note: candidate template ignored: substitution failure [with T = int]
    auto operator()(const T& v) const ->decltype(sub_expr::operator()(v))
         ^

So in summary: it appears that I got the decltype wrong, but I can’t figure out the correct way. Can anyone help me figure out what is causing these errors?

  • 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-06T02:17:21+00:00Added an answer on June 6, 2026 at 2:17 am

    Some of the errors I got from GCC suggested to me that there was an ambiguous base involved. Namely, expression_multiply<expression_parameter, expression_parameter> has expression_parameter as a (direct) base, and inherit_again<expression_parameter> which itself has expression_parameter as a base. This means that lhs::operator() is ambiguous in the scope of expression_multiply<expression_parameter, expression_parameter> (where lhs is in fact expression_parameter.

    A further fix was needed in that this was needed in the return type of operator(), resulting in the following fixes:

    // Instead of inherit_again
    template<int N, class sub_expr>
    class base : public sub_expr {
    public:
        base(sub_expr rhs): sub_expr(std::move(rhs)) {}
    };
    
    template<class lhs_given, class rhs_given>
    class expression_multiply: private base<0, lhs_given>, private base<1, rhs_given> {
        typedef base<0, lhs_given> lhs;
        typedef base<1, rhs_given> rhs;
    public:
        expression_multiply(lhs_given l, rhs_given r):lhs(std::move(l)), rhs(std::move(r)) {}
        template<class T>
        auto operator()(const T& v) const
        -> decltype(this->lhs::operator()(v) * this->rhs::operator()(v))
        {
            return lhs::operator()(v) * rhs::operator()(v);
        }
    };
    

    No idea if the compiler is behaving correcting regarding the need for those two ‘fixes’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a program that takes the information gathered from some calculations
I'm attempting to make a StateMachine execute some database action between states. So I
Greetings from some noob trying to learn JQuery, I am attempting to make it
Attempting to make a NSObject called 'Person' that will hold the login details for
I'm attempting to make a simple linear text game that will display inside a
I'm attempting to make use of the UIDocumentInteractionController mechanism in iPhone OS 3.2, but
I am attempting to make some data structures to solve a graph puzzle. I
Im attempting to make a little app that lets you add text boxes to
I am attempting to make some cross-DB(SQL Server and PostgreSQL) compatible SQL. What I
I am attempting to do some dynamic loading that includes javascript, css, and html

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.