469,156 Members | 2,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,156 developers. It's quick & easy.

Derived class fail to be called first from the base one

4 Nibble
I use Ipopt C++ project and I want to use it to solve my problem. I created a derived class from the base one and and I created a virtual function in the base class to modify it in the derived one by doing the following:
using namespace Ipopt;
base class : public TNLP
{
base class();

virtual ~base class();

public:
//I want fisrt to apply the routine to my problem, and I have to creat many member functions in the derived class. for this I creat //a simple virtual function
//all methods that are implement by Ipopt team are unchanged, and I modify the end of the code by making:
Protected:
virtual void sae(double aa_01, double ab_01, double ac_02, double ad_02);
};
class derived class: public base class
{
public:
derived class()
{}
virtual ~derived class()
{}
virtual void sae(double aa_01, double ab_01, double ac_02, double ad_02)
// then I define aa_01, ab_01, ac_02, ad_02
{
aa_01=22;
ab_01=222;
ac_02=0;
ad_02=10;
}
In Cpp file I make the following to call sae from derived class :
base class::base class()
{}
base class::~base class()
{}

void base class::sae(double aa_01, double ab_01, double ac_02, double ad_02)
{
base class *ptr = new derived class();
ptr->sae(aa_01, ab_01, ac_02, ad_02);
// and when attribute ptr to aa_01
aa_01_ = ptr->aa_01;
ab_01_ = ab_01;
ac_02_ = ac_02;
ad_02_ = ad_02;
}
//when I print the value of aa_01_ which is defined as private member in base class
the compiler shows derived class has no member named ‘aa_01’; did you mean ‘aa_01_’?
please help how can I resolve this? and how can I call, in cpp file, the derived class first and sepcified member in that class which contains the core of my problem
Thank you,
1 Week Ago #1
4 4193
dev7060
489 Expert 256MB
I use Ipopt C++ project and I want to use it to solve my problem. I created a derived class from the base one and and I created a virtual function in the base class to modify it in the derived one by doing the following:
using namespace Ipopt;
base class : public TNLP
{
base class();

virtual ~base class();

public:
//I want fisrt to apply the routine to my problem, and I have to creat many member functions in the derived class. for this I creat //a simple virtual function
//all methods that are implement by Ipopt team are unchanged, and I modify the end of the code by making:
Protected:
virtual void sae(double aa_01, double ab_01, double ac_02, double ad_02);
};
class derived class: public base class
{
public:
derived class()
{}
virtual ~derived class()
{}
virtual void sae(double aa_01, double ab_01, double ac_02, double ad_02)
// then I define aa_01, ab_01, ac_02, ad_02
{
aa_01=22;
ab_01=222;
ac_02=0;
ad_02=10;
}
In Cpp file I make the following to call sae from derived class :
base class::base class()
{}
base class::~base class()
{}

void base class::sae(double aa_01, double ab_01, double ac_02, double ad_02)
{
base class *ptr = new derived class();
ptr->sae(aa_01, ab_01, ac_02, ad_02);
// and when attribute ptr to aa_01
aa_01_ = ptr->aa_01;
ab_01_ = ab_01;
ac_02_ = ac_02;
ad_02_ = ad_02;
}
//when I print the value of aa_01_ which is defined as private member in base class
the compiler shows derived class has no member named ‘aa_01’; did you mean ‘aa_01_’?
please help how can I resolve this? and how can I call, in cpp file, the derived class first and sepcified member in that class which contains the core of my problem
Thank you,
Post the real and complete code you're compiling.
1 Week Ago #2
user9212
4 Nibble
@dev7060
I said that I use IPOPT and I implement a simple example to compile the program and I define a virtual function in base class (please see above) and redefine it in the derived one by attributing values to sae members, and when I call this function to print these value on the console the results are aa_01_=0 and ab_01_=0 . I use a pointer to base class but it does not give anything. I want to know how can I call functions implemented in the derived classs to file.cpp?
1 Week Ago #3
user9212
4 Nibble
Please I need your help
1 Week Ago #4
dev7060
489 Expert 256MB
@dev7060
I said that I use IPOPT and I implement a simple example to compile the program and I define a virtual function in base class (please see above) and redefine it in the derived one by attributing values to sae members, and when I call this function to print these value on the console the results are aa_01_=0 and ab_01_=0 . I use a pointer to base class but it does not give anything. I want to know how can I call functions implemented in the derived classs to file.cpp?
I doubt if the partial code posted in #1 even compiles; hence asked for the actual and complete code.
1 Week Ago #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Julia | last post: by
3 posts views Thread by Bit Byte | last post: by
15 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.