---what does "virtual int xfunc() = 0;" mean ?

B

Bill Zhao

Dear all,

Sorry for i did not paste original propreity codes
See below the fake codes for what I cannot understand.

===============================================
lass A
{
public:
virtual int xfunc() = 0 ;
virtual int yfunc() = 0 ;

};


class C: public A
{
int m_a;
int m_b;
public:
C();
~C();
int xfunc();
int yfunc();
};

the functions' inplementation is as

C::xfunc() {
........
}

========================================================
I am using the class C as my programming interface.
I am curious about the function of line "virtual int xfunc() = 0 ;"
I try read my c++ book and cannot got answer to this.


Thank you in advance

Bill Zhao
 
S

Sharad Kala

Bill Zhao said:
Dear all,

Sorry for i did not paste original propreity codes
See below the fake codes for what I cannot understand.

Read about pure virtual functions in your textbook.
 
D

David Hilsee

Bill Zhao said:
Dear all,

Sorry for i did not paste original propreity codes
See below the fake codes for what I cannot understand.

===============================================
lass A
{
public:
virtual int xfunc() = 0 ;
virtual int yfunc() = 0 ;

};


class C: public A
{
int m_a;
int m_b;
public:
C();
~C();
int xfunc();
int yfunc();
};

the functions' inplementation is as

C::xfunc() {
.......
}

========================================================
I am using the class C as my programming interface.
I am curious about the function of line "virtual int xfunc() = 0 ;"
I try read my c++ book and cannot got answer to this.

The "=0" means that the member function xfunc is a pure virtual function.
In a nutshell, that means that any class that derives from A must implement
xfunc or else it will be considered abstract (that is, it will be impossible
to create an instance of that class) and the "requirement" for implementing
xfunc is passed on to its subclasses. This feature is often useful when
creating "interface" functions and classes. I'm a little surprised that
your book doesn't cover pure virtual functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top