Thread: trying to inherit

  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,708
    Your header files are missing include guards.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

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, 02:10 PM