Well...that changes things. Okay, I'll have a look as soon as I get back.
That would fit, since I was learning Java for a while a couple of months back. In that case, where should I declare the function? In a separate header, or in the same one?
Well...that changes things. Okay, I'll have a look as soon as I get back.
That would fit, since I was learning Java for a while a couple of months back. In that case, where should I declare the function? In a separate header, or in the same one?
Where it belongs - meaning, if it's likely that you'd need it to be used in conjunection with whatever else is in that header, then there's no need for a new one.
A header-file should be relatively "complete on it's own". Having a whole bunch of little header files that you need to include all (or nearly all) of to make a useful program serves no purpose.
Obviously, if you have a large set of functions that belong together, then you would want to have that as a separate header, simply to keep the size of headers down. But that would be unusual.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Okay, one more question. I have a class that's made up entirely of static variables used throughout the program, such as screen size, number of objects, and general stuff like that. I'm next to positive that a class isn't the way to group them. So how should I? Should I make them global?
What exactly do you mean by "general stuff"?Originally Posted by G4B3
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Global variables are GENERALLY not the right solution. However, if you have a bunch of things that you need to access all over the program, making a structure that holds them, and have one global instance of that structure MAY be a solution.
Or make it a regular object, and pass it around (by (const) reference to the various places it is needed).
Or make it a singleton object.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
How is that different from just having global variables?However, if you have a bunch of things that you need to access all over the program, making a structure that holds them, and have one global instance of that structure MAY be a solution.
That's what I did in Java, but only because we can't have global variables in Java.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
You can also prefix your globals with g_. Now, what's the difference again?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
That works too - as long as it is actually done consistently.
As I said, ideally, you should have NO global data. But sometimes it's either awkward to get the right data from the place that knows the right stuff, to where it is needed later on (and it may need to persist across multiple object instance construction/destruction), so it is after all "better" to have a global collection of variables.
In my view, the standard method of a singleton class is pretty close to a global variable as well.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
What about putting them into a separate namespace rather than a class?
(although, from the sounds of it, I think a class is the right place)
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010