Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- Re: Strage behaviour un calling polymorphic functi...
General
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Latin America
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-30-2011 11:48 PM
03-30-2011 11:48 PM
Strage behaviour un calling polymorphic function
I am seeing very strage behaviour in my application in terms of calling polymorphic function through derived class object.
My base class has around 13 virtual/pure virtual functions.While calling one of pure virtual function (which is overridden by delived class) through derived class object pointer, I am seeing it is calling another pure virtual function ( the over ridden version of derived class).
To demonstrate it more clearly here is the example:
class base{
public:
virtual int func1()=0;
virtual int func2()=0;
};
clasee derived: public base
{
public:
int func1(){ return 7;}
int func2() { return 30;}
}
Now while calling func2() function: ptr->func2() ( where "ptr" contains derived object's address), it is calling ptr->func1(). This I came to kwno when I stepped in through code using gdb.
Note that in our application the base class code is a differetn compilation unit ( say unit1), derived class part in different compliation unit,unit2 ( of cource while compiling it refers the existing base class library ). At last the object creation of delrived class ( usign factory design ) and calling functions is in a third compilation unit(unit3).
This specific problem I am seeing if unit3 is not built with unit1 and unit2.As there is no code chnage in unit3 compilation unit, while execution it is referring updated unit1 and unit2. Under this circumstance I am facing the above mentioned problem( I am calling ptr->func2() but practically it is calling ptr->func1() )
Whether any specific rule of polymorphism missing here or any linking factor..
- Tags:
- virtual function
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
04-03-2011 11:59 AM
04-03-2011 11:59 AM
Re: Strage behaviour un calling polymorphic function
Is base in a common .h file that all units are including? And no #if to change the class members?
If you don't do this, you are violating the ODR rule where all definitions must match.
If you don't do this, you are violating the ODR rule where all definitions must match.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP