Hi everyone!
I'm working on a program that'll do a class of calculations common in chemistry. For this, there are a variety of information that I need to keep track of (i.e. positions of my atoms, type of calculation etc.).
From my reading, it seems that I have two options available: global class objects or static class objects. I'd like to go the static route as that seems to be a better option.
For starters, I have a class that looks like this (watered down):
read_inp.h:
1 2 3 4 5 6 7 8 9 10 11 12
|
class Read_Inp{
public:
.....
static string give_se_type(){return se_type};
.....
private:
....
static string se_type;
....
};
#include "read_inp.cc"
| |
And in my "read_inp.cc" I have
1 2 3
|
....
string Read_Inp::se_type;
....
| |
I then have a separate file for main:
1 2 3 4 5 6 7 8 9
|
int main(int argc, char *argv[]){
string file;
Read_Inp test;
file=argv[1];
read_input(file);
cout << "Testing static " << test.give_se_type() << endl;
}
| |
In the above segment, the nonmember function read_input() uses the Read_Inp class to set all the variables in that class. However, since that information would be local to only read_input(), I used static type to make it accessible outside of that class (using main for my test).
However, when I compile, I'm getting:
multiple definition of `Read_Inp::se_type'
|
Since I'm fairly new to C++ (I really started only a couple monthes ago), I don't know how to resolve this problem, and was wondering if any experts could chime in :)
Thanks!