Original Post
I am getting this error when I try to compile:
1>Particle.obj : error LNK2005: "struct SDL_Surface * red" (?red@@3PAUSDL_Surface@@A) already defined in main.obj
1>Particle.obj : error LNK2005: "struct SDL_Surface * blue" (?blue@@3PAUSDL_Surface@@A) already defined in main.obj
1>Particle.obj : error LNK2005: "struct SDL_Surface * green" (?green@@3PAUSDL_Surface@@A) already defined in main.obj
Source file:
Header File:
I know its because I include particles.h in this source file and in my main source file (I figured this out because I researched this type of error before positing).
I Really need red, green and blue to be global variables. what can I do to get rid of this error
1>Particle.obj : error LNK2005: "struct SDL_Surface * red" (?red@@3PAUSDL_Surface@@A) already defined in main.obj
1>Particle.obj : error LNK2005: "struct SDL_Surface * blue" (?blue@@3PAUSDL_Surface@@A) already defined in main.obj
1>Particle.obj : error LNK2005: "struct SDL_Surface * green" (?green@@3PAUSDL_Surface@@A) already defined in main.obj
Source file:
#include "Particle.h"
Particle::Particle(int X, int Y)
{
x = X + 5 + (rand()%25);
y = Y + 5 + (rand()%25);
frame = rand() % 5;
switch(rand()%3)
{
case 0:
type = red;
break;
case 1:
type = green;
break;
case 2:
type = blue;
break;
}
}Header File:
#pragma once
#include <SDL.h>
SDL_Surface *red;
SDL_Surface *green;
SDL_Surface *blue;
SDL_Surface *shimmer;
#ifndef PARTICLE
#define PARTICLE
class Particle
{
protected:
//offsets
int x,y;
// current frame of animation
int frame;
//type of particle
SDL_Surface* type;
public:
Particle(int X, int Y);
~Particle(void);
void show();
bool is_dead();
};
#endifI know its because I include particles.h in this source file and in my main source file (I figured this out because I researched this type of error before positing).
I Really need red, green and blue to be global variables. what can I do to get rid of this error