Reputation: 5684
I want to initialize all static variable objects to the same value. I have a class defined in prog1.h
namespace fal {
class read_f{
public:
static std::string ref_content, seq_content;
int read_fasta(int argc, char **argv);
};
}
And I tried to initialize them in prog1.cpp
std::string fal::read_f::ref_content = seq_content = "";
But I get undefined reference error
.
When I try
std::string fal::read_f::ref_content = "" ;
std::string fal::read_f::seq_content = "";
it works fine.
How can I initialize in one line?
Upvotes: 1
Views: 77
Reputation: 19019
You inline them with a comma. If you do not want to repeat the fal::
qualifier, you can use a using
declaration:
using fal::read_f;
std::string read_f::ref_content = "", read_f::seq_content = "";
Additionally, since C++17 you can make those two variables inline
, so that they may be defined in the class definition ([class.static.data]).
Upvotes: 3