【发布时间】:2020-12-08 06:41:24
【问题描述】:
我正在尝试构建一个具有公共函数的类,该类可以根据索引访问私有数组成员。
#include <iostream>
#include <array>
class foo{
public:
int get_value_from_table(int row_number){
return table[row_number];
}
private:
constexpr static std::array<int, 2> table = {1,2};
//void initialize_table();
};
int main() {
foo a;
int b = a.get_value_from_table(1);
std::cout << b << std::endl;
return 0;
}
构建代码时出现undefined symbol foo::table 错误。如何修复错误?
Undefined symbols for architecture x86_64:
"foo::table", referenced from:
foo::get_value_from_table(int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
【问题讨论】: