function redefinition error

This is a discussion on function redefinition error within the C Programming forums, part of the General Programming Boards category; hey guys, total newbie question here, but on this program I am writing I am, all of the sudden, getting ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    function redefinition error

    hey guys,
    total newbie question here, but on this program I am writing I am, all of the sudden, getting an error saying "redefinition of 'show_all_passengers' ", and I'm not sure why this is happening.
    Any help is really appreciated,
    thanks,
    John

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    You probably have an object (show_all_passengers) in a header somewhere that's getting included multiple times which to the compilers point of view is attempting to have several different objects with the same name created (this is bad). If this is the case, remove the objects declaration from the header (or at least make it "extern" within the header) and make sure an actual declaration exists only in a single source file.

    ... or something along those lines.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    963
    If indeed the compiler is reincluding a header more than once, you should look up "include guards":

    Include guard - Wikipedia, the free encyclopedia

    Code:
    /* contents of myheader.h */
    #ifndef MYHEADER_H
    #define MYHEADER_H
    /* code here */
    #endif
    Some compilers support the following:

    Code:
    /* first line of your header file */
    #pragma once
    which tells the compiler to only use that header once.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking to shlwapi.lib in C, MSVC CMD.
    By Joerge in forum Windows Programming
    Replies: 4
    Last Post: 08-07-2009, 05:18 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM

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