How to define static members in a static function in .cpp file?
-
@thippu Not really what I asked...
Did you adddouble AmpConfiguration::sampling_rate;
to your cpp file?
-
@jsulm yes bro, I did add like this
double AmpConfiguration::sampling_rate=line_list->at(0).toDouble();
but new error camequalified-id decalration before "=" token
Lifetime Qt Championwrote on 4 Feb 2019, 08:25 last edited by jsulm 2 Apr 2019, 08:27@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?:
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.wrote on 4 Feb 2019, 08:26 last edited by@jsulm said in How to define static members in a static function in .cpp file?:
Where do you call this now?
In the
mainwindow.cpp
-
@jsulm said in How to define static members in a static function in .cpp file?:
Where do you call this now?
In the
mainwindow.cpp
@thippu said in How to define static members in a static function in .cpp file?:
In the mainwindow.cpp
WHERE EXACTLY?
-
@thippu said in How to define static members in a static function in .cpp file?:
In the mainwindow.cpp
WHERE EXACTLY?
-
@jsulm
In the constructor of mainwindow.cpp
I'm callingAmpConfiguration::ReadIni();
First statement itself@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...
-
@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...
wrote on 4 Feb 2019, 08:41 last edited by@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 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...
wrote on 4 Feb 2019, 08:44 last edited by@jsulm said in How to define static members in a static function in .cpp file?:
AmpConfiguration::sampling_rate=line_list->at(0).toDouble();
No, change in the error. still, I'm getting undefined reference
-
@jsulm said in How to define static members in a static function in .cpp file?:
AmpConfiguration::sampling_rate=line_list->at(0).toDouble();
No, change in the error. still, I'm getting undefined reference
Lifetime Qt Championwrote on 4 Feb 2019, 08:54 last edited by jsulm 2 Apr 2019, 08:59@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++. -
@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++.wrote on 4 Feb 2019, 09:32 last edited by@jsulm said in How to define static members in a static function in .cpp file?:
// This has to be OUTSIDE of any method/constructor
Worked. bro
Thank you
16/16