#1. Don't use using namespace std;
1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
#2. Use separate translation units
2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.
#3. Don't use global variables
3. Don't use global variables
From Sprite.h
:
bool show = true;
Besides I don't get the purpose of that variable, you shouldn't use global variables to control the behavior of your code. If You're sure that you'll need a static variable for that make it a class member variable.
Also you'll get problems (multiple definition errors), if you include the header in multiple translation units.
#1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
#2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.
#3. Don't use global variables
From Sprite.h
:
bool show = true;
Besides I don't get the purpose of that variable, you shouldn't use global variables to control the behavior of your code. If You're sure that you'll need a static variable for that make it a class member variable.
Also you'll get problems (multiple definition errors), if you include the header in multiple translation units.
1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.
3. Don't use global variables
From Sprite.h
:
bool show = true;
Besides I don't get the purpose of that variable, you shouldn't use global variables to control the behavior of your code. If You're sure that you'll need a static variable for that make it a class member variable.
Also you'll get problems (multiple definition errors), if you include the header in multiple translation units.
#1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
#2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.
#3. Don't use global variables
From Sprite.h
:
bool show = true;
Besides I don't get the purpose of that variable, you shouldn't use global variables to control the behavior of your code. If You're sure that you'll need a static variable for that make it a class member variable.
Also you'll get problems (multiple definition errors), if you include the header in multiple translation units.
#1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
#2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.
#1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
#2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.
#3. Don't use global variables
From Sprite.h
:
bool show = true;
Besides I don't get the purpose of that variable, you shouldn't use global variables to control the behavior of your code. If You're sure that you'll need a static variable for that make it a class member variable.
Also you'll get problems (multiple definition errors), if you include the header in multiple translation units.
#1. Don't use using namespace std;
While that would work in your particular case, it's considered bad practice. Especially when you move out your code to separate header files.
See more details here please:
Why is "using namespace std;" considered bad practice?
#2. Use separate translation units
I was also wondering if I should make a .cpp file for each of my class header files, or is it ok to just put my methods with the header files.
Yes you should do that, unless you have template class implementations.
When doing so, it's very important to have header guards like
#ifndef CHARACTER_H
#define CHARACTER_H
// Class declaration of Character goes here ...
#endif // CHARACTER_H
or
#pragma once
// Class declaration of Character goes here ...
to prevent multiple declaration compiler errors.