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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:18:49+00:00 2026-06-12T15:18:49+00:00

I have a program that deals with operations in polynomials. An operator class has

  • 0

I have a program that deals with operations in polynomials. An “operator” class has a char pointer to the input string, a pointer to a function of type float (float, float) that is used to perform an operation on the arguments. Then there are a series of methods, setSymb(char *) points opChar to the argument, and points the opFunc pointer to the function that corresponds to the operator character. However when I run this method, and at the line where it assigns the function to the pointer function, there is an unhandled exception under new.cpp, when it tries to allocate memory of some sort. This confuses me a great deal.

#include "stckArrClassLib.h"
using namespace stacks;
using namespace conversion;

#define SIDE bool
#define LEFT 0
#define RIGHT 1

class oprt
{
public:
    typedef float (oprt::*fp)(float, float);
private:
    char *opSymb;
    fp opFunc;
    float *lOpnd;
    float *rOpnd;
    oprt *Lnext;
    oprt *Rnext;
    float rslt;
protected:
        float add(float a, float b){return a+b;};
    float mult(float a, float b){return a*b;};
    float div(float a, float b){return a/b;};
    float exp(float a, float b){return powf(a, b);};
    float par(float a, float b){return a;};
public:
    oprt (void) {opFunc=NULL;};
    oprt &setSymb(char *);
    oprt &setNext(SIDE, oprt *);
    oprt &setOpnd(SIDE, float);
    float evaluate();
    char *getSymb();
    fp getFunc();
    float *getOpnd(SIDE);
    oprt *getNext(SIDE);
};

oprt& oprt::setSymb(char *set)
{
        CArray<char, 8> opStr;
    opStr[0]=*(set), set;
    int i;
    for(i=1; i<7 && (!(set[i]>='0' && set[i]<='9') && !(set[i]=='+' || set[i]=='-' || opStr[i]=='*' || set[i]=='/' || set[i]=='^' || set[i]=='(')); i++)
    opStr[i]=set[i];
    opStr[i]=0;
    if(strcmp((const char *)opStr.arr, "+")==0)
            //problem is here
    opFunc=&oprt::add;
    else if(strcmp((const char *)opStr.arr, "*")==0)
            //and here
    opFunc=&oprt::mult;
    else if(strcmp((const char *)opStr.arr, "/")==0)
            //etc.
    opFunc=&oprt::div;
    else if(strcmp((const char *)opStr.arr, "^")==0)
    opFunc=&oprt::exp;
    else if(strcmp((const char *)opStr.arr, "(")==0 || strcmp((const char *)opStr.arr, ")")==0)
    opFunc=&oprt::par;
        return *this;
}

oprt& oprt::setNext(SIDE side, oprt *next)
{
    if(side==LEFT)
{
    Lnext=next;
    lOpnd=&(next->rslt);
}
else if(side==RIGHT)
{
    Rnext=next;
    rOpnd=&(next->rslt);
}
return *this;
}

float oprt::evaluate()
{
return rslt=(this->*opFunc)(*getOpnd(LEFT), *getOpnd(RIGHT));
}

char *oprt::getSymb()
{
return opSymb;
}

oprt::fp oprt::getFunc()
{
return opFunc;
}

float *oprt::getOpnd(SIDE side)
{
if(!((side==LEFT)? (Lnext==this):(Rnext==this)))
    (side==LEFT? Lnext:Rnext)->evaluate();
return (side==LEFT)? (lOpnd):(rOpnd);
}

oprt *oprt::getNext(SIDE side)
{
return (side==LEFT)? (Lnext):(Rnext);
}

oprt& oprt::setOpnd(SIDE side, float set)
{
(side==LEFT)? (*lOpnd=set):(*rOpnd=set);
return *this;
}

Here is the excerpt of new.cpp which is called at opFunc=&oprt::add in the function oprt& oprt::setSymb(char *)

extern "C" void * __cdecl _nh_malloc_dbg (
    size_t nSize,
    int nhFlag,
    int nBlockUse,
    const char * szFileName,
    int nLine
    )
{
    int errno_tmp = 0;
    void * pvBlk = _nh_malloc_dbg_impl(nSize, nhFlag, nBlockUse, szFileName, nLine, &errno_tmp);

    if ( pvBlk == NULL && errno_tmp != 0 && _errno())
    {
        errno = errno_tmp; // recall, #define errno *_errno()
    }
    return pvBlk;
}

The error is called when malloc is called.

  • 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-12T15:18:50+00:00Added an answer on June 12, 2026 at 3:18 pm

    I think you have to modify the typedef to this:

    typedef float (oprt::*fp)(float, float);
    

    You also don’t want to ommit the ‘&’ ampersand when assigning:

    opFunc=&oprt::mult;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have program that has a variable that should never change. However, somehow, it
I have a program that deals with huge amount of data. The process is
I have a program that deals with (virtual) money order transactions, and there are
I have to create a C# program that deals well with reading in huge
I have a C++ program that has the following form: int main(){ int answer;
I have a data structure in my C++ program that has some attributes of
I have a program that deals with command line args being sent to the
Hi I have a program that deals alot with vectors and indexes of the
So I have a program that deals with bytes. Everything works, except one part.
I have program that requires Python 3, but I develop Django and it uses

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.