hi, im trying to inherit from class but the same error is appearing
the following is my classesCode:1>c:\users\kthdu_000\documents\visual studio 2010\projects\rectangle\rectangle1\crectangle.h(1): error C2011: 'Crectangle' : 'class' type redefinition
crectangle.h
cperrect.hCode:class Crectangle{ protected: int m_x; int m_y; public: void setvalue(int x,int y); int getarea(void); };
Cperrect.cppCode:#include "Crectangle.h" class Cperrect : public Crectangle{ public : int perimter(); };
crectangle1.cppCode:#include "Cperrect.h" #include <iostream> int Cperrect::perimter(void){ int ans; ans =(m_x + m_y)*2; return ans; }
Main.cppCode:#include<iostream> #include"Crectangle.h" void Crectangle::setvalue(int x,int y){ m_x = x; m_y = y; } int Crectangle::getarea(void){ return m_x*m_y; }
Code:#include <iostream> #include "Crectangle.h" #include "Cperrect.h" void main(){ int x1=0,y1=0; Crectangle rect; Cperrect prect; std::cout<<"please enter 2 number"; std::cin>> x1>>y1; rect.setvalue(x1,y1); prect.setvalue(x1,y1); std::cout<< "area "<<rect.getarea(); std::cout<< "perimeter "<<prect.perimter(); }



LinkBack URL
About LinkBacks



