trying to inherit

This is a discussion on trying to inherit within the C++ Programming forums, part of the General Programming Boards category; hi, im trying to inherit from class but the same error is appearing Code: 1>c:\users\kthdu_000\documents\visual studio 2010\projects\rectangle\rectangle1\crectangle.h(1): error C2011: 'Crectangle' ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    trying to inherit

    hi, im trying to inherit from class but the same error is appearing
    Code:
    1>c:\users\kthdu_000\documents\visual studio 2010\projects\rectangle\rectangle1\crectangle.h(1): error C2011: 'Crectangle' : 'class' type redefinition
    the following is my classes

    crectangle.h
    Code:
    class Crectangle{
    
    
    protected:
    	int m_x;
    	int m_y;
    public:
        void setvalue(int x,int y);
    	int getarea(void);
    };
    cperrect.h
    Code:
    
    #include "Crectangle.h"
    
    
    class Cperrect : public Crectangle{
    
    
    
    
    public  :
    
    
    	int perimter();
    
    
    
    
    };
    Cperrect.cpp
    Code:
    #include "Cperrect.h"
    #include <iostream>
    
    
    int Cperrect::perimter(void){
    	int ans;
    
    
    	ans =(m_x + m_y)*2;
    
    
    
    
    	return ans;
    }
    crectangle1.cpp
    Code:
    #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;
     }
    Main.cpp
    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();
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Your header files are missing include guards.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    Also: SourceForge.net: Void main - cpwiki
    And using "void" in the parameter list when it takes no parameters in C++ is an archaic convention. You don't need it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I inherit static data members ?
    By manasij7479 in forum C++ Programming
    Replies: 22
    Last Post: 03-12-2012, 08:19 AM
  2. Templates don't inherit typenames? (GCC specific)
    By QuestionD in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2011, 08:58 AM
  3. to inherit or not to inherit ...
    By Greenhorn__ in forum C++ Programming
    Replies: 16
    Last Post: 09-01-2008, 11:37 AM
  4. How properly inherit from template?
    By 6tr6tr in forum C++ Programming
    Replies: 118
    Last Post: 04-25-2008, 04:30 AM
  5. Class design (inherit or not)
    By Raigne in forum Game Programming
    Replies: 4
    Last Post: 03-03-2008, 01:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21