473,396 Members | 1,810 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.

Pure virtual methods cannot be inherit?

Rafael Justo
Check the following code example:

Expand|Select|Wrap|Line Numbers
  1. ///////////////////////
  2.  
  3. class A
  4. {
  5. public:
  6.   int a;
  7. };
  8.  
  9. ///////////////////////
  10.  
  11. class B : public A {};
  12.  
  13. ///////////////////////
  14.  
  15. class C
  16. {
  17. public:
  18.   virtual void c(A *a) = 0;
  19. };
  20.  
  21. ///////////////////////
  22.  
  23. class D : public C
  24. {
  25.   void c(B *b) {}
  26. };
  27.  
  28. ///////////////////////
  29.  
  30. int main()
  31. {
  32.   D d;
  33.   return 0;
  34. }
  35.  
The compiler gives me the following error:
cannot declare variable ‘d’ to be of abstract type ‘D’ because the following virtual functions are pure within ‘D’: virtual void C::c(A*)

I don't understand why the compiler doesn't accept it. The object used in the parameter is an extension of the original one used in the abstract class.

Any ideas?

Best regards,
Rafael
Jul 21 '10 #1
1 1796
newb16
687 512MB
They can be inherited, but the argument list must be the same - the fact that B is inherited from A doesn't matter.
Jul 21 '10 #2

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

Similar topics

51
by: Noam Raphael | last post by:
Hello, I thought about a new Python feature. Please tell me what you think about it. Say you want to write a base class with some unimplemented methods, that subclasses must implement (or...
4
by: qazmlp | last post by:
I have a base class('base') containing 10 public pure virtual menthods. I have a class(derivedOne) deriving from 'base'. derivedOne implements only 7 of those base methods. Now, is it a good style...
2
by: Mitch Mooney | last post by:
Subject line says it all. For example: //base class class foo{ public: foo(); ~foo(); virtual ??? GetValue()=0; };
6
by: John | last post by:
I'm inheriting from multiple abstract base classes (2 to be exact). In the inherited class I want to know if I can implement two pure virtual methods (one from each base class) having the same...
5
by: Ruben Campos | last post by:
I've recently noticed that it's not allowed to call a pure (non-implemented) virtual method inside a constructor or a destructor, doesn't matter if this method is declared in the considered class...
2
by: vilarneto | last post by:
Hello everyone, I'm facing a particular situation about template class derivation. The subject is old -- deriving a non-template class from a template base class -- but my problem is that the...
1
by: a2z | last post by:
From design point of view, I have other work around to get following behavior of pure virtual methods: 1. To make a class abstract I can make constructor/destructor private. What is the thing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.