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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:53:57+00:00 2026-06-12T18:53:57+00:00

Assume proper headers are included. I have a class for various functions of a

  • 0

Assume proper headers are included.

I have a class for various functions of a calculator. I have several structs for different operator types (nullary, Unirary, Binary, Ternary). I want to initialize that a vector(or preferably an array) of the structs with the elements filled in for w/e my calculator supports. For example nul[]={{pi, "pi"}, {ans, "ans"}}; My program will then take a token from the input and search for the appropriate operator, return the index of that operator, and then i’d invoke the proper function pointer. My problem is initializing an array or vector in the constuctor. I’d appreciate it if someone could show me both ways. thank you. Below is my class and unfinished constructor. Also if u can think of a better way for me to write my calculator I’d love to hear it.

//operator class
class Functions{
    public:
        Functions();
        double pi(double x=0);
        double answer(double& x);
        double abs(double& x);
        double pow(double& x);
        double add(double& x, double &y) const;
        double subtract(double& x, double& y) const;
        double multiply(double& x, double& y)const;
        double divide(double& x, double& y) const;
        double max(double& x, double& y, double& z) const;
        double volume(double& x, double& y, double& z) const;
        void doc();
        bool weird(double &x) const;
        unsigned findop0(const string & name);
        unsigned findop1(const string & name);
        unsigned findop2(const string & name);
        unsigned findop3(const string & name);
    private:
        struct Nul{
            double (*nulf)(double & x);
            string name;
        };
        struct Uni{
            bool (*unif)( double & result, double x );
            string name;
        };
        struct Bin{
            bool (*binf)( double & result, double x, double y );
            string name;
        };
        struct Tern{
            bool (*terf)( double & result, double x, double y, double z );
            string name;
        };
        static const unsigned NUL_ELEMENTS = 2;
        static const unsigned UNI_ELEMENTS = 2;
        static const unsigned BIN_ELEMENTS = 4;
        static const unsigned TRI_ELEMENTS = 2;
        vector<Nul> nul;
        vector<Uni> uni;
        vector<Bin> bin;
        vector<Tern> tri;
};

Functions::Functions(){
    nul
}
  • 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-12T18:53:58+00:00Added an answer on June 12, 2026 at 6:53 pm

    In C++11 you can do this in one line, in initialization list.

    struct C {
      int a[20];
      int* b;
      std::vector<int> c;
      std::array<int,20> d;
      C() : 
         a({1,2,3}), 
         b(new int[20]{1,2,3}), 
         c({1,2,3}), 
         d(std::array<int, 20u>{1,2,3}) 
      {}
    };
    

    In C++03 use multiline assignments or make static function to initialize vector or raw array.

    struct C {
      int a[20];
      int* b;
      std::vector<int> c;
      C() : 
         b(new int[20]), 
      {
         a[0] = 1; ...
         b[0] = 1;
         c.push_back(1);
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class Foo (assume proper using directives) namespace Example { [XmlRoot(foo)] class
Assume I have a class implementing two or more COM interfaces (exactly as here
Assume I have a bean DialogBox, with properties for height and width: public class
Let's assume I have a proper Date object constructed from the string: Tue Jan
assume I have this little model: class Deal(models.Model): purchases = models.IntegerField(default=0)#amount of purchases so
lets assume I have following model: class Note(models.Model): user = models.ForeignKey(User) pub_date = models.DateTimeField()
Assume I have a Class Foo which has many internal variables, only one constructor
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----
Assume I have an enumerable object enum and now I want to get 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.