Thread: Multiple Definition

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    Unhappy Multiple Definition

    Hi, I'm kind of not doing so hot at this whole programming thing. Could someone tell me what I'm doing wrong here?
    Code:
    //main.cpp
    #include <iostream>
    #include "pr.cpp"
    using namespace std;
    
    int main()
    {
            p();
    	return 0;
    }
    
    //pr.cpp
    #include "pr.h"
    int p()
    {
        return 0;
    }
    
    //pr.h
    
    #ifndef _PR_H
    #define _PR_H
    int p();
    #endif
    /home/workspace/programming/testing/pr.cpp:2: multiple definition of `p()'
    obj/Debug/pointer.o:/home/workspace/programming/testing/pr.cpp:2: first defined here
    :: === Build finished: 2 errors, 0 warnings ===

    I would appreciate it.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > #include "pr.cpp"
    This should be
    #include "pr.h"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Phantom redefinition
    By CodeMonkey in forum C++ Programming
    Replies: 6
    Last Post: 06-12-2005, 05:42 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM