Hey guys i'd really appreciate some help with this, I'm trying to compile the following incredibly basic program (as you can see) but getting errors from the compiler that make no sense to me! :confused:
I've put all the code below, and then a copy of the error messages I'm getting. (by the way I do understand the concept of a class and I do realise a namespace would be better suited for the following but I was working on something using a class that failed and I figured since this also fails exactly the same way, this would be easier for you all to read through)
The Code
test.h - Defines the class
Code:#pragma once
class test
{
public:
double sum(double base, double add); // function to add "add" to "base" as double
};
test.cpp - Provides the function
Code:#include "test.h"
double test::sum(double base, double add)
{
return base + add;
}
main.cpp - Program start point
Code:#include <iostream>
#include "test.cpp"
using namespace std;
int main()
{
test myTest;
cout << "The Sum Of 5 And 4 Is: " << myTest.sum(5, 4) << "\n";
return 0;
}
The Errors
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2005: "public: double __thiscall test::sum(double,double)" (?sum@test@@QAENNN@Z) already defined in test.obj
1>C:\Users\...\Documents\Visual Studio 2008\Projects\class_test\Debug\class_test.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://c:\Users\...\Documents\Visual Studio 2008\Projects\class_test\class_test\Debug\BuildLog.htm"
1>class_test - 2 error(s), 0 warning(s)

