How to define static members in a static function in .cpp file?
-
@thippu said in How to define static members in a static function in .cpp file?:
double AmpConfiguration::sampling_rate=line_list->at(0).toDouble();
Please read again what I wrote.
Where do you call this now?
It looks like you're now trying to declare a LOCAL variable with same name which is for sure not what you want to do. -
@thippu said in How to define static members in a static function in .cpp file?:
In the mainwindow.cpp
WHERE EXACTLY?
-
@thippu Can you actually be more precise when answering questions?
Do you mean you put that line in the constructor or inside ReadIni()?
But as I said: you're declaring a local variable with same name.
It must be like this:AmpConfiguration::sampling_rate=line_list->at(0).toDouble();
AmpConfiguration:: can be removed as well...
-
@jsulm said in How to define static members in a static function in .cpp file?:
local variable
I would like it to be a global static variable.
and I would like to use it(initialize) inside
AmpConfiguration::ReadIni()
@jsulm said in How to define static members in a static function in .cpp file?:
AmpConfiguration::sampling_rate=line_list->at(0).toDouble();
finally, Calling the
AmpConfiguration::ReadIni()
in constructor ofmainwindow.cpp
. -
@thippu "I would like it to be a global static variable." - then why do you declare it as local variable?
Did you putdouble AmpConfiguration::sampling_rate=10.2; // This has to be OUTSIDE of any method/constructor void AmpConfiguration::ReadIni() { sampling_rate=line_list->at(0).toDouble(); }
as I already wrote above?
Please read about static members in C++.