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

pure virtual function with body

Hi All,

1.Please check this code and its output which is working fine
while pure virtual functions( FUN1) prototype of Class CA is different
then Class CB Function (FUN1).

2. In Class CA pure virtual function ( FUN1) have body.

3. If i change my second pure virtual function(FUN2) prototype
class CA----> virtual int fun2()=0;
class CB---> void fun2(){ cout <<" fun of CB void::CB fun2() "<<endl;}

i am getting following error

$ CC -o CoVariance CoVariance.cpp
"CoVariance.cpp", line 24: Error: Virtual function CB::fun2() returns void, while CA::fun2() returns int.
1 Error(s) detected.

Can any one help me to find this dual behavior of code ?
#include<iostream>
using namespace std;

class CA
{
public:
CA()
{cout<<"CA::CA()"<<endl;}
virtual CA& fun1()=0;
virtual void fun2()=0;
virtual ~CA()
{cout<<"CA::~CA()"<<endl;}
};
void CA::fun2(){ cout <<"pure virtual fun of CA void::CA fun2() "<<endl;}

class CB:public CA
{
public:
CB()
{cout<<"CB::CB()"<<endl;}
~CB()
{cout<<"CB::~CB()"<<endl;}
CB& fun1(){ cout <<"CB fun1() "<<endl;return *this;}
void fun2(){ CA::fun2();}
};

int main()
{
CA *p = new CB;
p->fun1();
p->fun2();
delete p;
return (0);
}


OUTPUT:--
$ CC -o CoVariance CoVariance.cpp
$ ./CoVariance
CA::CA()
CB::CB()
CB fun1()
pure virtual fun of CA void::CA fun2()
CB::~CB()
CA::~CA()
$
Nov 23 '07 #1
1 2248
weaknessforcats
9,208 Expert Mod 8TB
I have no idea what your error is about.

Your code compiles and links with no errors or warnings using Visual Studio.NET 2005.
Nov 24 '07 #2

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

Similar topics

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...
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
6
by: pakis | last post by:
I am having a problem of pure virtual function call in my project. Can anyone explaine me the causes of pure virtual function calls other than calling a virtual function in base class? Thanks
21
by: sks | last post by:
Hi , could anyone explain me why definition to a pure virtual function is allowed ?
3
by: Dmitry Prokoptsev | last post by:
Hello, I need to write a class for exceptions which can be thrown, caught, stored and thrown once again. I have written the following code: --- begin --- #include <string> class Exception...
10
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a...
7
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to what is the exact difference between a virtual function and a pure virtual function? Thanks in advance!!!
10
by: Rahul | last post by:
Hi, I tried to create a abstract class by having a non-virtual member function as pure, but i got a compilation error saying "only virtual member functions can be pure"... I'm trying to think...
14
by: Jack | last post by:
Hi, I meet a question with it , I did not get clear the different betteen them, for example: #include <iostream>
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.