error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '

Discussion in 'C++' started by BlueTrin, Apr 4, 2006.

  1. BlueTrin

    BlueTrin Guest

    Hello I was adapting a C version of SolvOpt in C++ to use it within a
    virtual class.

    However I am stuck with the overriding of evaluation and gradiant
    functions.



    cStepCurveEvaluator.cpp
    cStepCurveEvaluator.cpp(14) : error C2296: '.*' : illegal, left operand
    has type 'cStepCurveEvaluator *const '
    cStepCurveEvaluator.cpp(15) : error C2296: '.*' : illegal, left operand
    has type 'cStepCurveEvaluator *const '
    cStepCurveEvaluator.cpp(16) : error C2296: '.*' : illegal, left operand
    has type 'cStepCurveEvaluator *const '


    The Class I defined is:

    class cSolvOpt
    {
    private:
    virtual double fun(double x[]) = 0;
    virtual double func(double x[]) = 0;
    virtual double grad(double x[],double g[]) = 0;
    virtual double gradc(double x[],double g[]) = 0;

    public:
    cSolvOpt(void);
    ~cSolvOpt(void);

    double cSolvOpt::solvopt(unsigned short n,
    double x[],
    double options[]
    );

    void cSolvOpt::apprgrdn ( unsigned short n,
    double g[],
    double x[],
    double f,
    double (cSolvOpt::*fun)(double*),
    double deltax[],
    unsigned short obj);
    };


    And I would like to override only fun as func, grad and gradc are not
    used. The class cSolvOpt is checking if func grad and gradc a function
    pointers equal to NULL.

    Is there any way to NOT override these members or to initialize them to
    NULL ?

    Cheers
    Anthony
     
    BlueTrin, Apr 4, 2006
    #1
    1. Advertising

  2. BlueTrin

    Howard Guest

    "BlueTrin" <> wrote in message
    news:...
    > Hello I was adapting a C version of SolvOpt in C++ to use it within a
    > virtual class.
    >
    > However I am stuck with the overriding of evaluation and gradiant
    > functions.
    >
    >
    >
    > cStepCurveEvaluator.cpp
    > cStepCurveEvaluator.cpp(14) : error C2296: '.*' : illegal, left operand
    > has type 'cStepCurveEvaluator *const '
    > cStepCurveEvaluator.cpp(15) : error C2296: '.*' : illegal, left operand
    > has type 'cStepCurveEvaluator *const '
    > cStepCurveEvaluator.cpp(16) : error C2296: '.*' : illegal, left operand
    > has type 'cStepCurveEvaluator *const '
    >
    >


    You don't show where the code is which is generating these errors. What's a
    cStepEvaluator?

    > The Class I defined is:
    >
    > class cSolvOpt
    > {
    > private:
    > virtual double fun(double x[]) = 0;
    > virtual double func(double x[]) = 0;
    > virtual double grad(double x[],double g[]) = 0;
    > virtual double gradc(double x[],double g[]) = 0;
    >
    > public:
    > cSolvOpt(void);
    > ~cSolvOpt(void);
    >
    > double cSolvOpt::solvopt(unsigned short n,
    > double x[],
    > double options[]
    > );
    >
    > void cSolvOpt::apprgrdn ( unsigned short n,
    > double g[],
    > double x[],
    > double f,
    > double (cSolvOpt::*fun)(double*),
    > double deltax[],
    > unsigned short obj);
    > };
    >
    >
    > And I would like to override only fun as func, grad and gradc are not
    > used. The class cSolvOpt is checking if func grad and gradc a function
    > pointers equal to NULL.
    >
    > Is there any way to NOT override these members or to initialize them to
    > NULL ?
    >


    You cannot instantiate a class which has any "pure virtual" member
    functions. That's what you have above, with the "= 0" specified after each
    function. You need to override those and provide bodies for them if you
    want to actually create an instance of a class derived from cSolvOpt. If
    you don't use the functions, just take some appropriate action, such as
    returning 0, or throwing an exception. But they do need to be implemented.

    -Howard
     
    Howard, Apr 4, 2006
    #2
    1. Advertising

  3. BlueTrin

    BlueTrin Guest

    Sorry, here is the class. I would like to assign 0 to func, grad and
    gradc (a NULL pointer), is that invalid in C++ ?

    cStepCurveEvaluator::cStepCurveEvaluator(vector<cMultiVarPolynom*>&
    vec_Equs, double *dblEquVals)
    : vec_Equations(vec_Equs)
    , dbl_Equations_values(dblEquVals)
    {
    this->*func = NULL;
    this->*grad = NULL;
    this->*gradc = NULL;
    }

    class cStepCurveEvaluator
    : public cSolvOpt
    {
    private:
    double* CalcValues(double * values);
    double fun(double * values);
    double func(double x[]) {return 0.0;};
    double grad(double x[],double g[]) {return 0.0;};
    double gradc(double x[],double g[]) {return 0.0;};
    public:
    vector<cMultiVarPolynom*>& vec_Equations;
    double* dbl_Equations_values;

    cStepCurveEvaluator(vector<cMultiVarPolynom*>& vec_Equs, double
    *dblEquVals);
    ~cStepCurveEvaluator(void) {;}
    };

    Compiling...
    cStepCurveEvaluator.cpp
    cStepCurveEvaluator.cpp(13) : fatal error C1001: INTERNAL COMPILER
    ERROR
    (compiler file 'msc1.cpp', line 2701)
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more
    information

    Build log was saved at "file://c:\Users\Stusd\GenLib
    0.0.5\GenLib-IRD\Debug\BuildLog.htm"
    GenLib-IRD - 1 error(s), 0 warning(s)
     
    BlueTrin, Apr 4, 2006
    #3
  4. BlueTrin

    BlueTrin Guest

    Ok I got it, I need to implement them ...

    Is there any way to assign a null pointer to a member function ? is
    that forbidden in C++ ?
     
    BlueTrin, Apr 4, 2006
    #4
  5. BlueTrin

    Howard Guest

    "BlueTrin" <> wrote in message
    news:...
    > Ok I got it, I need to implement them ...
    >
    > Is there any way to assign a null pointer to a member function ? is
    > that forbidden in C++ ?
    >


    It's not possible in C++.

    You can assign NULL to a pointer-to-a-function (member or otherwise), but
    that's not the same thing.

    The name of the function is not a pointer to the function (although it's
    conceivable that someone could implement their compiler that way, I
    suppose). When you add "= 0" to the declaration of the function in the
    class definition, you tell the compiler it's a "pure virtual" function.
    There is no way to tell the compiler, other than making a function pure
    virtual, that you don't want to implement it. And if it's not implemented,
    then you can't (directly) create an instance of the class.

    Just implement the functions, giving them some kind of simplistic behavior
    (including throwing an exception?) and document somewhere that they should
    not be used.

    -Howard
     
    Howard, Apr 4, 2006
    #5
  6. Hello,

    BlueTrin wrote:

    > Ok I got it, I need to implement them ...
    >
    > Is there any way to assign a null pointer to a member function ? is
    > that forbidden in C++ ?


    No, you cannot assign anything to a member function. The = 0 in the
    class definition makes the class an abstract class, i.e. there are no
    direct instances of that class, but only of subclasses implementing
    those methods and not making the subclass abstract again. It is
    possible to provide an implementation of a method and declaring it
    abstract, i.e. the =0 is completely orthogonal to providing an
    implementation. Both cannot be changed at runtime.

    You could use member function pointers to get something you can "assign"
    different methods of the same class with the same signature to at
    runtime.

    class abc
    {
    public:
    abc();

    char func1(int){}

    typedef char (abc::*MemberFctPtr)(int);
    MemberFctPtr mfp;
    };

    abc::abc()
    : mfp(&abc::func1)
    {
    // mfp = &abc::func1; // assignment
    }

    Bernd
     
    Bernd Strieder, Apr 4, 2006
    #6
  7. BlueTrin

    BlueTrin Guest

    Thank you for your answers I have defined some booleans to indicate if
    the functions have been overloaded and should been used.
     
    BlueTrin, Apr 5, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Mierzejewski
    Replies:
    2
    Views:
    1,922
    Ron Natalie
    Jun 25, 2003
  2. Kostatus

    "illegal operand" error

    Kostatus, Jul 25, 2003, in forum: C++
    Replies:
    2
    Views:
    655
    Rolf Magnus
    Jul 25, 2003
  3. s88
    Replies:
    3
    Views:
    1,118
    Jim Langston
    Sep 23, 2010
  4. Prasoon Saurav
    Replies:
    1
    Views:
    548
  5. pc
    Replies:
    2
    Views:
    1,391
    crisgoogle
    Jun 8, 2011
Loading...

Share This Page