473,396 Members | 1,907 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,396 software developers and data experts.

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,
Sep 14 '21 #1
4 7131
dev7060
636 Expert 512MB
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.
Sep 15 '21 #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?
Sep 15 '21 #3
user9212
4 Nibble
Please I need your help
Sep 17 '21 #4
dev7060
636 Expert 512MB
@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.
Sep 18 '21 #5

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

Similar topics

10
by: Bhan | last post by:
Using Ptr of derived class to point to base class and viceversa class base { .... } class derived : public base { .... }
10
by: Julia | last post by:
Hi Please can someone explain this behaviour: I have a MustInherit Base class and a Derived class that Inherits Base and Shadows a method in the base class. If I Dim a variable of type...
3
by: Bit Byte | last post by:
Must be the time of the day, but I seem to get my head in a spin over this ... I have a base class B, from which I have a derived class. In class B, i have a (public access) typedef of a...
15
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I met with a strange issue that derived class function can not access base class's protected member. Do you know why? Here is the error message and code. error C2248:...
1
by: user9212 | last post by:
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.