By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Bill Zhao" <sz*****@tom.com> wrote in message
news:cf**********@mail.cn99.com...
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.
Jul 22 '05 #2

P: n/a
"Bill Zhao" <sz*****@tom.com> wrote in message
news:cf**********@mail.cn99.com...
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.

--
David Hilsee
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.