472,784 Members | 861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 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:
Expand|Select|Wrap|Line Numbers
  1. using namespace Ipopt;
  2. class base : public TNLP
  3. {
  4.   base();
  6.   virtual ~base();
  8. public:
  9. //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 
  10. //a simple virtual function 
  11. //all methods that are implement by Ipopt  team are unchanged, and I modify the end of the code by making:
  12. Protected:
  13.   virtual void sae(double aa_01, double ab_01, double ac_02, double ad_02);
  14. };
  15. class derived_class: public base
  16. public:
  17.   derived_class()
  18.   {}
  19.   virtual ~derived_class()
  20.   {}
  21.   virtual void sae(double aa_01, double ab_01, double ac_02, double ad_02)
  22.   // then I define aa_01,  ab_01, ac_02,  ad_02
  23.   {
  24.     aa_01=22;
  25.     ab_01=222;
  26.     ac_02=0;
  27.     ad_02=10;
  28.   }
In Cpp file I make the following to call sae from derived class :
Expand|Select|Wrap|Line Numbers
  1. base ::base ()
  2. {}
  3. base :~base()
  4. {}
  6. void base::sae(double aa_01, double ab_01, double ac_02, double ad_02)
  7. {
  8.   base *ptr = new derived_class();
  9.   ptr->sae(aa_01, ab_01, ac_02, ad_02);
  10.   // and when attribute ptr to aa_01    
  11.   aa_01_ = ptr->aa_01;
  12.   ab_01_ =  ab_01;
  13.   ac_02_ =  ac_02;
  14.   ad_02_ = ad_02;
  15. }
//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 specified member in that class which contains the core of my problem
Thank you,
Sep 14 '21 #1
1 7119
9,065 Expert Mod 8TB
None of your classes, base or derived, have any data members in the code you have posted. Additionally you are using a base class pointer so even if you had defined data members in derived you would not be able to access them through that pointer.
Sep 20 '21 #2

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

Similar topics

by: Bhan | last post by:
Using Ptr of derived class to point to base class and viceversa class base { .... } class derived : public base { .... }
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...
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...
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:...
by: sedrel | last post by:
Hello All, I'm new to C++ (been an Ada guy for over 20 years), and I've search but can't find an answer to my question on the Web (big place!), so I'm hoping you Gurus come help me. I know that...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.