+ Reply to Thread
Results 1 to 2 of 2

Thread: Does this code use C++ polymorphism?

  1. #1

    Does this code use C++ polymorphism?

    Code:
    class CShape
    {
    public:
    	void Parameter(int n, int x) {} ; 
    } ;
    
    class CSquare : public CShape
    {
    public:
    	void Parameter(double n, double x) {} ; 
    } ;
    Any comment?

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    37
    No, this is not the case of polymorphism.

    Polymorphism applies where you create an method in base class having 'virtual' keyword.

    You then derive a class from the base and define new method in the derive class having the same signature in the base class!

    Example:

    Code:
    class CShape
    {
    public:
    	virtual void Parameter(int n, int x) {} ; //Note: keyword 'virtual'
    } ;
    
    class CSquare : public CShape
    {
    public:
    	virtual void Parameter(int n, int x) {} ; //Note: same method signature as base class!
    } ;

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts