【问题标题】:Unresolved External Array未解析的外部数组
【发布时间】:2018-06-22 22:03:54
【问题描述】:

我正在做一个学校项目,我遇到了“未解析的外部符号”的链接器错误我有两个文件; math.h 和 math.cpp。我试图在 math.h 的命名空间中声明一些数组,但我收到了链接器错误。在我的 math.h 中:

namespace domath
{
extern float alpha1[];
extern Vector ecth[];
}

在我的 math.cpp 中:

#include math.h

float alpha1[];
Vector ecth[];

我能做些什么来解决?我无法分配像 alpha1[] = {1} 这样的值,因为我不知道它将具有的值。提前非常感谢!

【问题讨论】:

  • 没有数组。

标签: c++ linker unresolved-external


【解决方案1】:

您在 domath 命名空间中声明数组,但在全局命名空间中定义它们。试试这个:

// math.cpp

#include math.h

namespace domath
{
float alpha1[];
Vector ecth[];
}

它不起作用的另一个原因是您没有指定数组的大小。要么预先给它们一个固定大小,要么将它们声明为指针,或者——通常在 C++ 中最好——使用std::vector

【讨论】:

  • Stll 不起作用 :(。请注意,我稍后在代码中更改了数组的值,例如;domath::ecth[alpha1->GetIndex()] = 9;
猜你喜欢
  • 2016-05-10
  • 2019-09-03
  • 2015-08-17
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-16
  • 2011-02-09
相关资源
最近更新 更多