Thread: Redefinition of classes (#include headers)

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    38

    Redefinition of classes (#include headers)

    What is the best way to avoid the: 'class' type redefinition errors? This comes from anytime I include a header for a file that has already been included somewhere else. First of all, why is this a problem, and second, what a quick and easy way to fix this.

    thanks

    -from looking at previous post it looks like my answer has something to do with either "using namespace std" or "#ifndef"
    chris

  2. #2
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    for example, a main.h file
    Code:
    #ifndef _MAIN_H
    #define _MAIN_H
    
    //...............code here
    
    #endif

  3. #3
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    First of all, why is this a problem
    You can't declare or define things twice.

    and second, what a quick and easy way to fix this.
    Use inclusion guards, as EvBladeRunnervE has shown.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    To add to ' EvBladeRunnervE' post...

    Code:
    #ifndef _MAIN_H
    #define _MAIN_H
    
    #ifndef _STDIO_H
    #include <stdio.h>
    #endif 
    
    #ifndef _STDLIB_H
    #include <stdlib.h>
    #endif 
    
    //...............code here
    
    #endif // !_MAIN_H
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. does not name a type ERROR
    By DarrenY in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2007, 04:54 AM
  2. classes, inheritance and include problems
    By baniakjr in forum C++ Programming
    Replies: 6
    Last Post: 12-12-2006, 01:45 PM
  3. Headers and Classes
    By MMD_Lynx in forum Game Programming
    Replies: 2
    Last Post: 12-01-2004, 10:40 AM
  4. Headers, Classes, and Functions question.
    By Zeusbwr in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2004, 03:18 AM
  5. How do I include Headers and Libs with Borland 3.1?
    By fatpotatohead in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 02:27 PM