Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '

Reply
Thread Tools

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

 
 
BlueTrin
Guest
Posts: n/a
 
      04-04-2006
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

 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      04-04-2006

"BlueTrin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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




 
Reply With Quote
 
 
 
 
BlueTrin
Guest
Posts: n/a
 
      04-04-2006
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<cM ultiVarPolynom*>&
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)

 
Reply With Quote
 
BlueTrin
Guest
Posts: n/a
 
      04-04-2006
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++ ?

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      04-04-2006

"BlueTrin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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



 
Reply With Quote
 
Bernd Strieder
Guest
Posts: n/a
 
      04-04-2006
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

 
Reply With Quote
 
BlueTrin
Guest
Posts: n/a
 
      04-05-2006
Thank you for your answers I have defined some booleans to indicate if
the functions have been overloaded and should been used.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TypeError: 'in <string>' requires string as left operand, not Element Victor Hooi Python 4 12-10-2012 02:42 AM
left shift operator behaves like left rotate when the operand is a variable. pc C Programming 2 06-08-2011 06:58 PM
Why does left shift operation invoke Undefined Behaviour when theleft side operand has negative value? Prasoon Saurav C++ 1 09-24-2010 06:07 PM
left-hand operand of comma has no effect s88 C++ 3 09-23-2010 06:02 PM
Another Curious C++ Error - Illegal Left Operand Tim Mierzejewski C++ 2 06-25-2003 09:37 PM



Advertisments