Click here to Skip to main content
15,867,328 members
Articles / Programming Languages / C

Polymorphism in C

Rate me:
Please Sign up or sign in to vote.
4.92/5 (45 votes)
5 Jul 2005CPOL21 min read 247.9K   5.7K   109  
The article demonstrates how to implement polymorphism using the C language.
#ifndef __CLASS_H__
#define __CLASS_H__

class X
{
public:
	X();
	virtual ~X();

	virtual void One();
	virtual void Two();
	virtual void Three();

protected:
	char className[8];
	int x;
};

class Y : public X
{
public:
	Y();
	~Y();

	void One();

protected:
	int y;
};

class Z : public Y
{
public:
	Z();
	~Z();

	void Two();

protected:
	int z;
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Santosh works as a Technical Architect in God's own Country, Kerala, India. He has been involved with C/C++ since 1996. Started with a few game clones and then went on to commercial software. He started his stint with software training and then went on to professional software development, design and architecture. Unix and C were his favorite in his early days but later grew very fond of Windows especially with the release of Windows NT 4.0 and Visual C++ 6.0. Technologies like COM and .Net fascinate him. He still lurks around Unix once in a while.

Music and the guitar are his second favorites and he manages to impress his friends with these skills when there are nobody better than him around. He is a patient and fun loving character who does not think too much about the future. He hates wasting time and so is working hard (in his dreams) to perfect instant transportation and time travel.

Oh! Yes. He loves Superman. Always did and always will. He would love to become a Superman and rid the world of all evil.

He used to be a Microsoft Visual C++ MVP (October 2009 - September 2013)

Comments and Discussions