Last active
November 1, 2017 17:12
-
-
Save deanhu2/9d75f7cacb7b1b8bc8efd1bd87f7faeb to your computer and use it in GitHub Desktop.
Minimal example of a shape interface and extending it to create a basic square object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
Online C++ Compiler. | |
Code, Compile, Run and Debug C++ program online. | |
Write your code in this editor and press "Run" button to compile and execute it. | |
*******************************************************************************/ | |
#include <iostream> | |
using namespace std; | |
struct IShape | |
{ | |
virtual ~IShape() {}; | |
virtual void setWidth(int width) const = 0; | |
virtual void setHeight(int height) const = 0; | |
virtual void setX(int x) const = 0; | |
virtual void setY(int y) const = 0; | |
virtual int getX() const=0; | |
virtual int getY() const=0; | |
virtual int getWidth() const=0; | |
virtual int getHeight() const=0; | |
}; | |
struct Square : public IShape | |
{ | |
Square(): m_x(0),m_y(0),m_width(100),m_height(100){}; | |
Square(int x,int y,int width,int height){}; | |
virtual void setWidth(int width)const{}; | |
virtual void setHeight(int height) const{}; | |
virtual void setX(int x) const{}; | |
virtual void setY(int y) const{}; | |
virtual int getX() const{return m_x;}; | |
virtual int getY() const{return m_y;}; | |
virtual int getWidth() const{return m_width;}; | |
virtual int getHeight() const{return m_height;}; | |
private: | |
int m_width; | |
int m_height; | |
int m_x; | |
int m_y; | |
}; | |
int main() | |
{ | |
Square sq; | |
cout<< "X:"<<sq.getX()<<" y:"<<sq.getY()<<" Width:"<<sq.getWidth()<<" Height:"<<sq.getHeight(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment