- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在参数中使用 std::string
时遇到问题:
MyClass
有一个这样的方法
public:
void loadDatas(string filename);
在我的 main.cpp
中,我有以下简单代码:
#include <iostream>
#include <string>
#include "myclass.hpp";
using namespace std;
int main()
{
string foo = "test.txt";
cout << foo << endl; // Print Hello Kitty, no problems
MyClass i;
// The following line raise :
// obj/Release/src/main.o||In function `main':|
// main.cpp|| undefined reference to `MyClass::loadDatas(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
// ||=== Build finished: 1 errors, 0 warnings ===|
i.loadDatas(foo);
return EXIT_SUCCESS;
}
因此看起来 libstdc++
链接良好(因为我能够使用 cout
打印文本),但是传递了一个 string
在参数中引发错误,我不明白为什么。
有人可以帮我吗?
编辑:我犯了一个错误,实际上是 i.loadDatas(foo);
(我更正了)。我的源代码不是英文的,所以我试着用英文为你做了一个简单的版本。我真的调用实例方法而不是静态方法。
编辑 2:完整的源代码
personnage.hpp
#ifndef PERSONNAGE_H
#define PERSONNAGE_H
#include <iostream>
#include <string>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include "carte.hpp"
using namespace std;
class Personnage : public Carte
{
public:
Personnage();
void chargerPersonnage(string nom);
virtual ~Personnage();
private:
//! Le texte d'accroche de la carte
string _accroche;
};
#endif // PERSONNAGE_H
personnage.cpp
#include "personnage.hpp"
Personnage::Personnage() : Carte("Sans titre")
{
}
void chargerPersonnage(string nom)
{
}
Personnage::~Personnage()
{
//dtor
}
main.cpp
#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
#include "personnage.hpp"
using namespace sf;
using namespace std;
int main()
{
string test = "Hello Kitty";
cout << test << endl;
Personnage test2;
test2.chargerPersonnage(test);
return EXIT_SUCCESS;
}
错误日志
obj/Release/src/main.o||In function `main':|
main.cpp|| undefined reference to `Personnage::chargerPersonnage(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
||=== Build finished: 1 errors, 0 warnings ===|
最佳答案
问题是您已经将 class Personnage
定义为具有成员函数 chargerPersonnage
,但是在 personnage.cpp 中您定义了一个 < strong>免费功能 chargerPersonnage
代替。
您似乎知道正确的语法,就像您正确地执行了 Personnage
的构造函数和析构函数一样,但只是为了说明:更改 void chargerPersonnage(string nom) { }
到 personnage.cpp 中的 void Personnage::chargerPersonnage(string nom) { }
。
关于c++ - main.cpp ||对 `MyClass::loadDatas(std::basic_string<char, std::char_traits<char>, std::allocator<char>>)' 的 undefined reference |,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5523562/
我只是有一个更琐碎的问题。 为什么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
我是一名优秀的程序员,十分优秀!