- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在头文件中有以下内容。
namespace silc{
class pattern_token_map
{
/* Contents */
};
pattern_token_map* load_from_file(const char*);
}
在 CPP 文件中(这有适当的包含)
pattern_token_map* load_from_file(const char* filename)
{
// Implementation goes here
}
在另一个 CPP 文件中。这已经包含了所有正确的内容。
void some_method()
{
const char* filename = "sample.xml";
pattern_token_map* map = load_from_file( filename ); // Linker complains about this.
}
我收到一个链接器错误,指出对 load_from_file
的 undefined reference 。我看不出这里出了什么问题。
如有任何帮助,我们将不胜感激。
编译器:G++操作系统:Ubuntu 9.10
编辑
这是使用的链接器命令。
g++ -L/home/nkn/silc-project/third_party/UnitTest++ -o tests.out src/phonetic_kit/pattern_token_map.o tests/pattern_token_map_tests.o tests/main.o -lUnitTest++
错误来自 pattern_token_map_tests.o
,该函数在 pattern_token_map.o
中可用。所以我想链接的顺序不是问题。 (我从命令中删除了一些文件以简化它)
最佳答案
当你实现它的时候,你必须确保你实现了正确的功能:
namespace silc {
pattern_token_map* load_from_file(const char* filename) {
// Implementation goes here
}
}
如果您改为这样做:
using namespace silc; // to get pattern_token_map
pattern_token_map* load_from_file(const char* filename) {
// Implementation goes here
}
那么您将定义一个新函数,而不是 silc::load_from_file。
避免在函数范围之外使用指令(“using namespace ...;”),作为一般准则:
using namespace silc; // outside function scope: avoid
silc::pattern_token_map* // qualify return type
random_function(silc::pattern_token_map* p) { // and parameters
using namespace silc; // inside function scope: fine
pattern_token_map* p2 = 0; // don't have to qualify inside the function
// if you want to use the using directive
silc::pattern_token_map* p3 = 0; // but you can always do this
return 0;
}
关于c++ - 对非成员函数的 undefined reference - C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2081905/
我只是有一个更琐碎的问题。 为什么undefined == undefined 返回true,而undefined >= undefined 为false? undefined 等于 undefine
用PHP 7.2编写套接字服务器。根据Firefox 60中的“网络”选项卡,服务器的一些HTTP响应的第一行随机变为undefined undefined undefined。因此,我尝试记录套接字
在 JavaScript 中这是真的: undefined == undefined 但这是错误的: undefined <= undefined 起初我以为<=运算符包含第一个,但我猜它试图将其转换
在回答这个问题 (Difference between [Object, Object] and Array(2)) 时,我在 JavaScript 数组中遇到了一些我以前不知道的东西(具有讽刺意味的
来自https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/of , Note: thi
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
当我添加 到我的 PrimeFaces Mobile 页面,然后我在服务器日志中收到以下警告 WARNING: JSF1064: Unable to find or serve resource, u
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我正在运行 PHP 脚本并继续收到如下错误: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php
我是一名优秀的程序员,十分优秀!