linker error in simple program: multiple definition of function

Posted by BillyJean on Stack Overflow See other posts from Stack Overflow or by BillyJean
Published on 2013-06-28T10:09:16Z Indexed on 2013/06/28 10:21 UTC
Read the original article Hit count: 331

Filed under:
|
|

My function test is added to two different .cpp-files and the functions are private to their respective files as shown below

test1.cpp

#include <iostream>

using namespace std;

void test()
{
    cout << "test" << endl;
}

test2.cpp

#include <iostream>

using namespace std;

void test()
{
    cout << "test" << endl;
}

main.cpp

#include <iostream>

using namespace std;



int main()
{

    return 0;
}

During linking I get the error multiple definition of test() - but how is that possible, considering that the two files have their own private scope!? I could understand it if I included the function prototype in each .cpp-files' corresponding header, but there is no such thing in this example.

© Stack Overflow or respective owner

Related posts about c++

Related posts about linker