无法使用我的 C++ 中的对象来推送_front() 标准库列表;

发布于 2024-07-20 13:58:34 字数 518 浏览 3 评论 0 原文

我有一个类,我想使用标准库列表来存储它们的列表。 我本质上想 Push_front() 列表。 所以我的代码是这样的:

#include <list>
/* ... lots of stuff ...*/

complexNode myObject();

std::list<complexNode> complexList();

myList.push_front(myObject);

但是编译器抛出这个错误:

error: request for member 'push_front' in 'complexList', which is of non-class type 'std::list > ()()'

类 ComplexNode 有一个复制构造函数。

我真的不明白这个问题以及该错误的实际含义......请帮忙!

I have an class and I would like to use the standard library list to store a list of them. I essentially want to push_front() the list. So my code is like this:

#include <list>
/* ... lots of stuff ...*/

complexNode myObject();

std::list<complexNode> complexList();

myList.push_front(myObject);

But the compiler throws this error:

error: request for member ‘push_front’ in ‘complexList’, which is of non-class type ‘std::list<complexNode, std::allocator<complexNode> > ()()’

The class complexNode has a copy contructor.

I really don't understand the problem and what that error actually means... please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩套路吗 2024-07-27 13:58:34
std::list<complexNode> complexList();

这不应该是:

std::list<complexNode> complexList; // without the () 
std::list<complexNode> complexList();

shouldn't this be :

std::list<complexNode> complexList; // without the () 
把回忆走一遍 2024-07-27 13:58:34

此:

std::list<complexNode> complexList();

具有通用名称“C++ 最令人烦恼的解析"。 简而言之,您已将complexList 设为返回列表的函数的声明,而不是局部变量。 去掉(),那么它就不能被解析为函数。

This:

std::list<complexNode> complexList();

Has the common name "C++'s most vexing parse". In short, you have made complexList be the declaration of a function that returns a list, instead of a local variable. Remove the (), then it cannot be parsed as a function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文