473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

Apr 4 '06 #1
6 13519

"BlueTrin" <bl******@gmail.com> wrote in message
news:11*********************@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


Apr 4 '06 #2
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)

Apr 4 '06 #3
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++ ?

Apr 4 '06 #4

"BlueTrin" <bl******@gmail.com> wrote in message
news:11**********************@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

Apr 4 '06 #5
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

Apr 4 '06 #6
Thank you for your answers I have defined some booleans to indicate if
the functions have been overloaded and should been used.

Apr 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Koekenberg | last post by:
Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call...
3
by: Rakesh | last post by:
In my Python code fragment, I want to write a code fragment such that the minimum element of a tuple is subtracted from all the elements of a given tuple. When I execute the following python...
2
by: Tim Mierzejewski | last post by:
You guys were so great with answering my first question that I've decided to ask you yet again! Again, only the relevant code is included. typedef unsigned int unint; #include <iostream> ...
3
by: yaffa | last post by:
hey folks i get this error: Python interpreter error: unsupported operand type(s) for |: when i run this line of code: for incident in bs('tr', {'bgcolor' : '#eeeeee'} | {'bgcolor' :...
8
by: makita18v | last post by:
Hey I'm really new to programming and I can't figure out what I'm doing wrong. So I was asked to write a program that determines whether a year is a leap year or not. So I wrote the following formula...
3
by: StrugglingStudent | last post by:
I'm having problems finishing my program, it keeps giving me the error '=':function as left operand. And im not sure what that means. It is supposed to be a function to calculate basic car rental...
15
by: Fuzz13 | last post by:
I'm writing a program that a user loads a file (txt or csv) in which it reads newlines and commas as new object delimiters. Each new object is put into an array creating a new array object each time....
2
by: Mark05 | last post by:
#include<conio.h> #include<iostream> using namespace std; int main() { double ManfCode,ProdCode; int Checkdigit, SecondManf, FourthManf; int FirstProd,ThirdProd,FifthProd; int...
1
by: Terry Archer | last post by:
error C2296: '%' : illegal,left operand has type 'double' #include <iostream> #include <fstream> #include <iomanip> using namespace std; const int OUNCES_PER_POUND = 16; const double...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.