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

  • Home
  • SEARCH
  • 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 235845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:17:52+00:00 2026-05-11T20:17:52+00:00

I am working on making an expression class: template<typename T, typename U> class expression

  • 0

I am working on making an expression class:

template<typename T, typename U>
class expression
{
public:
    expression(T vala, U valb, oper o){val1 = vala; val2 = valb; op = o;}
    operator bool{return(val1 op val2);}
private:
    T val1;
    U val2;
    oper op;
};

as you can see, this is somewhat pseudocode, because I need an operator class. My original thought was to create an array of all possible operators, and then convert it through a string, but that wouldn’t work because of the sheer number of operators, and how to convert it to a string except through a two dimensional array, where n[0][0] has the first operator, and n[0][1] has that operators string.

Does anybody have any suggestions to adding an operator value to my expression class?

  • 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-05-11T20:17:52+00:00Added an answer on May 11, 2026 at 8:17 pm

    Maybe a function pointer. Instead of …

    operator bool{return(val1 op val2);}
    

    … code it as …

    operator bool{return op(val1, val2);}
    

    … in which case op can be a pointer to a (any) function which takes two parameters and which returns bool.

    template<typename T, typename U>
    class expression
    {
    public:
        //define pointer-to-function type
        typedef bool *oper(const T& val1, const U& val2);
        ... etc ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on making an HTTP server for my class. But, the returned file
I'm working on making an interface for a robot. My Robot class has methods
I'm working on making a simple server application with python, and I'm trying to
I'm working on making 3 VM versions of XP with IE6, 7, and 8
I'm working on making an ASCII based game, and everywhere I look people are
I am working on making a new SQLite database. Obviously for a number of
I am working on making a simple drawing program. So far I am able
I am working on making a twitter client app. One of the requirement of
I am working on making user pages for a certain type of user who
I'm working on making some code using metaheuristics for finding good solutions to the

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.