我正在努力理解术语静态手段及其工作原理。在这里,我初始化了一个静态变量“浮动百分比”。我必须使用 convertToPercent() 将其转换为百分比,转换后我必须取值并将值放入 someMethod() 进行一些计算
下面是我所拥有的
。H
class Foo {
private:
static float percentage;
public :
float convertToPercent();
};
.cpp
float Foo::convertToPercent() {
percentage = (30/100) * 100;
return percentage;
}
static float someMethod () {
//place the static percentage value here after doing convertToPercent() method to do some calculation;
}
但是它向我抛出了一条错误消息
Undefined symbols for architecture x86_64:
"Foo::percentage", referenced from:
Foo::convertToPercent() in Foo.o
感谢给予的帮助。谢谢