- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Strage behaviour un calling polymorphic functi...
Operating System - Linux
1753261
Members
4688
Online
108792
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
- 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
- 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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP