Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const ' (http://www.velocityreviews.com/forums/t453071-error-c2296-illegal-left-operand-has-type-cstepcurveevaluator-const.html)

BlueTrin 04-04-2006 02:35 PM

error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '
 
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


Howard 04-04-2006 03:11 PM

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

"BlueTrin" <bluetrin@gmail.com> wrote in message
news:1144161319.359363.56650@v46g2000cwv.googlegro 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





BlueTrin 04-04-2006 03:28 PM

Re: error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '
 
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)


BlueTrin 04-04-2006 03:30 PM

Re: error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '
 
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++ ?


Howard 04-04-2006 04:27 PM

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

"BlueTrin" <bluetrin@gmail.com> wrote in message
news:1144164600.860377.220580@e56g2000cwe.googlegr 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




Bernd Strieder 04-04-2006 04:31 PM

Re: error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '
 
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


BlueTrin 04-05-2006 10:45 AM

Re: error C2296: '.*' : illegal, left operand has type 'cStepCurveEvaluator *const '
 
Thank you for your answers I have defined some booleans to indicate if
the functions have been overloaded and should been used.



All times are GMT. The time now is 04:33 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.