There are many questions on this, but none solve my problem. I am trying to use multiple files. I have no idea where the problem is, so I will include all the top lines (#include, #pragma, etc.)
This problem arose when I was creating the class for Cubes.cpp (and in Cubes.h).
main.cpp
#include <iostream>
#include "Cubes.h"
#include "Common functions.h"
#include "Global.h"
#include <SFML/Graphics.hpp>
Cubes.cpp
#include <iostream>
#include "Cubes.h"
#include "Common functions.h"
#include "Global.h"
#include <SFML\Graphics.hpp>
#include <vector>
#include <string>
// Later on in code, where I think it went wrong:
Render::Render()
{
this->rot;
this->boxCoords;
this->rlBoxCol;
this->gridSize;
this->cubeSize;
this->offset;
}
void Render::setRotation(std::vector<float> setRot)
{ // Set rotation
rot = setRot;
}
std::vector<float> Render::getRotation()
{ // Get rotation
return rot;
}
void Render::setCoordinates(std::vector<int> setBoxCoords)
{
boxCoords = setBoxCoords;
}
std::vector<int> Render::getCoordinates()
{
return boxCoords;
}
void Render::setColours(std::vector<std::string> setRlBoxCol)
{
rlBoxCol = setRlBoxCol;
}
std::vector<std::string> Render::getColours()
{
return rlBoxCol;
}
void Render::setSizeOfGrid(int setGridSize)
{
gridSize = setGridSize;
}
int Render::getSizeOfGrid()
{
return gridSize;
}
void Render::setSizeOfCubes(int setCubeSize)
{
cubeSize = setCubeSize;
}
int Render::getSizeOfCubes()
{
return cubeSize;
}
void Render::setOffset(std::vector<int> setOffset)
{
offset = setOffset;
}
std::vector<int> Render::getOffset()
{
return offset;
}
void Render::display()
{
// Long code, not going to show it
}
Cubes.h
#pragma once
#include <vector>
#include <string>
// Also later on in Cubes.h ...
class Render
{
private:
std::vector<float> rot;
std::vector<int> boxCoords;
std::vector<std::string> rlBoxCol;
int gridSize;
int cubeSize;
std::vector<int> offset;
public:
Render();
void setRotation(std::vector<float> setRot);
std::vector<float> getRotation();
void setCoordinates(std::vector<int> setBoxCoords);
std::vector<int> getCoordinates();
void setColours(std::vector<std::string> setRlBoxCol);
std::vector<std::string> getColours();
void setSizeOfGrid(int setGridSize);
int getSizeOfGrid();
void setSizeOfCubes(int setCubeSize);
int getSizeOfCubes();
void setOffset(std::vector<int> setOffset);
std::vector<int> getOffset();
void display();
};
Common functions.cpp
#include <iostream>
#include "Common functions.h"
#include <vector>
#include <string>
Common functions.h
#pragma once
#include <vector>
Global.h
#pragma once
#include <SFML\Graphics.hpp>
extern sf::RenderWindow Window(sf::VideoMode(500, 500), "Maximize window to play the game");
extern std::string status = "NULL";
With the errors:
LNK2005
"class sf::RenderWindow Window" (?Window@@3VRenderWindow@sf@@A) already defined in Cubes.obj
C:\Users\George\Documents\C++\Projects\Don't fall\Don't fall\main.obj 1
.
LNK2005
"class std::basic_string,class std::allocator > status" (?status@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Cubes.obj
C:\Users\George\Documents\C++\Projects\Don't fall\Don't fall\main.obj 1
.
LNK1169
one or more multiply defined symbols found
C:\Users\George\Documents\C++\Projects\Don't fall\Debug\Don't fall.exe 1
.
I have been stuck on this problem for a while, so any help would be greatly appreciated!
EDIT
I answered my own question, as no one found a solution.