Errors
Error 1 error LNK2005: "class Foo Foo" (?Foo@@3V0@A) already defined in Bar.obj
Error 2 error LNK1169: one or more multiply defined symbols found
Bar.hpp
#ifndef _BAR_HPP
#define _BAR_HPP
class Foo
{
public:
Foo();
~Foo();
void SetInt(const int&);
int GetInt();
int var;
}Foo;
class Bar
{
public:
Bar(const int&);
~Bar();
int GetInt();
private:
};
#endif
Bar.cpp
#include "Bar.hpp"
Foo::Foo()
{
var = 0;
}
Foo::~Foo()
{
var = 0;
}
void Foo::SetInt(const int& value)
{
var = value;
}
int Foo::GetInt()
{
return var;
}
Bar::Bar(const int& value)
{
Foo.SetInt(value);
}
Bar::~Bar()
{
}
int Bar::GetInt()
{
return Foo.GetInt();
}
Main.cpp
#include <iostream>
#include "Bar.hpp"
using namespace std;
int main(int argc, char* argv[])
{
Bar bar(25);
cout << "Bar: " << bar.GetInt() << endl;
return 0;
}