Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+中通过引用传递对象+;_C++_Pass By Reference - Fatal编程技术网

C++ 在C+中通过引用传递对象+;

C++ 在C+中通过引用传递对象+;,c++,pass-by-reference,C++,Pass By Reference,在人们开始告诉我用谷歌搜索我的问题之前,让我说我已经尝试了很长一段时间了 我无法计算如何在C++中引用一个对象,我一直在获得大量编译器错误的打印输出。如果他们愿意帮忙,我可以把他们包括在内。具体来说,我试图通过引用线程中的函数parseFeed来传递RSSFeed对象提要 void parseFeed(RSSFeed& feed) { //dostuff } RSSFeed feed(); thread(parseFeed, feed); // line 119 错误: g+

在人们开始告诉我用谷歌搜索我的问题之前,让我说我已经尝试了很长一段时间了

<>我无法计算如何在C++中引用一个对象,我一直在获得大量编译器错误的打印输出。如果他们愿意帮忙,我可以把他们包括在内。具体来说,我试图通过引用线程中的函数parseFeed来传递RSSFeed对象提要

void parseFeed(RSSFeed& feed) {
    //dostuff
}

RSSFeed feed();
thread(parseFeed, feed); // line 119
错误:

g++ -g -Wall -pedantic -O0 -std=c++0x -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD -I/usr/class/cs110/include/libxml2 -I/usr/class/cs110/local/include   -c -o news-aggregator.o news-aggregator.cc
In file included from /usr/include/c++/4.6/functional:56:0,
                 from /usr/include/c++/4.6/bits/stl_algo.h:68,
                 from /usr/include/c++/4.6/algorithm:63,
                 from news-aggregator.cc:14:
rss-feed.h: In constructor âconstexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long unsigned int _Idx = 0ul, _Head = RSSFeed]â:
/usr/include/c++/4.6/tuple:162:44:   instantiated from âconstexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 0ul, _Head = RSSFeed, _Tail = {}]â
/usr/include/c++/4.6/tuple:423:24:   instantiated from âconstexpr std::tuple<_T1>::tuple(const _T1&) [with _T1 = RSSFeed]â
/usr/include/c++/4.6/functional:1362:70:   instantiated from âstd::_Bind_result<_Result, _Functor(_Bound_args ...)>::_Bind_result(_Functor&&, _Args&& ...) [with _Args = {RSSFeed&}, _Result = void, _Functor = void (*)(RSSFeed&), _Bound_args = {RSSFeed}]â
/usr/include/c++/4.6/functional:1477:41:   instantiated from âtypename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type std::bind(_Functor&&, _ArgTypes&& ...) [with _Result = void, _Functor = void (&)(RSSFeed&), _ArgTypes = {RSSFeed&}, typename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type = std::_Bind_result<void, void (*(RSSFeed))(RSSFeed&)>]â
/usr/include/c++/4.6/thread:135:9:   instantiated from âstd::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(RSSFeed&), _Args = {RSSFeed&}]â
news-aggregator.cc:119:25:   instantiated from here
rss-feed.h:54:3: error: âRSSFeed::RSSFeed(const RSSFeed&)â is private
/usr/include/c++/4.6/tuple:97:25: error: within this context
/usr/include/c++/4.6/tuple:97:25: error: use of deleted function âRSSFeed::RSSFeed(const RSSFeed&)â
rss-feed.h:54:3: error: declared here
rss-feed.h: In constructor âstd::_Head_base<_Idx, _Head, false>::_Head_base(_UHead&&) [with _UHead = RSSFeed, long unsigned int _Idx = 0ul, _Head = RSSFeed]â:
/usr/include/c++/4.6/tuple:174:43:   instantiated from âstd::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 0ul, _Head = RSSFeed, _Tail = {}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<0ul, RSSFeed>]â
/usr/include/c++/4.6/tuple:434:51:   instantiated from âstd::tuple<_T1>::tuple(std::tuple<_T1>&&) [with _T1 = RSSFeed, std::tuple<_T1> = std::tuple<RSSFeed>]â
/usr/include/c++/4.6/functional:1368:78:   instantiated from âstd::_Bind_result<_Result, _Functor(_Bound_args ...)>::_Bind_result(std::_Bind_result<_Result, _Functor(_Bound_args ...)>&&) [with _Result = void, _Functor = void (*)(RSSFeed&), _Bound_args = {RSSFeed}, std::_Bind_result<_Result, _Functor(_Bound_args ...)> = std::_Bind_result<void, void (*(RSSFeed))(RSSFeed&)>]â
/usr/include/c++/4.6/functional:1477:41:   instantiated from âtypename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type std::bind(_Functor&&, _ArgTypes&& ...) [with _Result = void, _Functor = void (&)(RSSFeed&), _ArgTypes = {RSSFeed&}, typename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type = std::_Bind_result<void, void (*(RSSFeed))(RSSFeed&)>]â
/usr/include/c++/4.6/thread:135:9:   instantiated from âstd::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(RSSFeed&), _Args = {RSSFeed&}]â
news-aggregator.cc:119:25:   instantiated from here
rss-feed.h:54:3: error: âRSSFeed::RSSFeed(const RSSFeed&)â is private
/usr/include/c++/4.6/tuple:101:42: error: within this context
/usr/include/c++/4.6/tuple:101:42: error: use of deleted function âRSSFeed::RSSFeed(const RSSFeed&)â
rss-feed.h:54:3: error: declared here
g++-g-Wall-pedantic-O0-std=c++0x-D_GLIBCXX_USE_NANOSLEEP-D_GLIBCXX_USE_SCHED_YIELD-I/usr/class/cs110/include/libxml2-I/usr/class/cs110/local/include-c-o新闻聚合器.o新闻聚合器.cc
在/usr/include/c++/4.6/functional:56:0中包含的文件中,
从/usr/include/c++/4.6/bits/stl_algo.h:68,
来自/usr/include/c++/4.6/算法:63,
来自新闻聚合器。抄送:14:
rss feed.h:在构造函数–constexpr std::_Head_base::_Head_base(const _Head&)[长无符号int _Idx=0ul,_Head=RSSFeed]中--
/usr/include/c++/4.6/tuple:162:44:实例化自-constexpr std::\u tuple\u impl::\u tuple\u impl(const\u Head&,const\u Tail&…)[长无符号int\u Idx=0ul,\u Head=RSSFeed,\u Tail={}]
/usr/include/c++/4.6/tuple:423:24:实例化自–constepr std::tuple::tuple(const_T1&)[with_T1=RSSFeed]
/usr/include/c++/4.6/functional:1362:70:实例化自–std::_Bind_result::_Bind_result(_Functor&&,_Args&&&…[带_Args={RSSFeed&},_result=void,_Functor=void(*)(RSSFeed&)),_Bind_Args={RSSFeed}
/usr/include/c++/4.6/functional:1477:41:实例化自–typename std::_Bindres_helper::type std::bind(_Functor&,_ArgTypes&&&…[带_Result=void,_Functor=void(&)(RSSFeed&),_ArgTypes={RSSFeed},typename std:_Bindres_helper&::type=std:_bind&&&&&&&&&&…[带&&u Result=void(&)]
/usr/include/c++/4.6/thread:135:9:实例化自–std::thread::thread(_Callable&&,_Args&&…[带_Callable=void(&)(RSSFeed&)),_Args={RSSFeed&}
新闻聚合器。cc:119:25:从此处实例化
RSSFeed.h:54:3:error:RSSFeed::RSSFeed(const-RSSFeed&)是私有的
/usr/include/c++/4.6/tuple:97:25:error:在此上下文中
/usr/include/c++/4.6/tuple:97:25:错误:使用了已删除的函数&RSSFeed::RSSFeed(const-RSSFeed&)
rss提要.h:54:3:错误:此处声明
rss feed.h:在构造函数中–std::_Head\u base::_Head\u base(_UHead&&)[with-u UHead=RSSFeed,long unsigned int\u Idx=0ul,_Head=RSSFeed]
/usr/include/c++/4.6/tuple:174:43:实例化自–std::\u tuple\u impl::\u tuple\u impl(std::\u tuple\u impl&)[长无符号int\u Idx=0ul,\u Head=RSSFeed,\u Tail={},std:\u tuple\u impl=std:\u tuple\u impl=std:\u tuple\u impl]
/usr/include/c++/4.6/tuple:434:51:实例化自–std::tuple::tuple(std::tuple&)[with_T1=RSSFeed,std::tuple=std::tuple]
/usr/include/c++/4.6/functional:1368:78:实例化自–std::_Bind_result::_Bind_result&)[带_result=void,_Functor=void(*)(RSSFeed&),_Bind_args={RSSFeed},std:_Bind_result=std:_Bind:_Bind_result=std:_Bind_result=std:_Bind_result]
/usr/include/c++/4.6/functional:1477:41:实例化自–typename std::_Bindres_helper::type std::bind(_Functor&,_ArgTypes&&&…[带_Result=void,_Functor=void(&)(RSSFeed&),_ArgTypes={RSSFeed},typename std:_Bindres_helper&::type=std:_bind&&&&&&&&&&…[带&&u Result=void(&)]
/usr/include/c++/4.6/thread:135:9:实例化自–std::thread::thread(_Callable&&,_Args&&…[带_Callable=void(&)(RSSFeed&)),_Args={RSSFeed&}
新闻聚合器。cc:119:25:从此处实例化
RSSFeed.h:54:3:error:RSSFeed::RSSFeed(const-RSSFeed&)是私有的
/usr/include/c++/4.6/tuple:101:42:错误:在此上下文中
/usr/include/c++/4.6/tuple:101:42:错误:使用了已删除的函数&RSSFeed::RSSFeed(const-RSSFeed&)
rss提要.h:54:3:错误:此处声明
已解决: 线程(parseFeed,ref(feed);//第119行

RSSFeed feed();
是一个函数声明,返回RSSFeed类型的对象,并且没有参数。它不是对象定义

改写

RSSFeed feed;
从错误消息列表中还可以看出,类RSSFeed没有定义为已删除的复制构造函数

这个

RSSFeed feed();
是一个函数声明,返回RSSFeed类型的对象,并且没有参数。它不是对象定义

改写

RSSFeed feed;

从错误消息列表中还可以看出,类RSSFeed没有定义为已删除的复制构造函数

此问题称为一个
vexing parse
,请参阅/***构造函数:RSSFeed*用法:RSSFeed feed(“);*-----------------------------------------------------------------------------------------------*围绕提供的URL构造一个RSSFeed对象。*/RSSFeed(const std::string&URL):URL(URL){}我不认为这是问题所在,我省略了构造函数的参数,但当我使用feed作为变量时,代码工作得很好。@MaxBozzi不,这只是一个麻烦的解析。最麻烦的解析应该是
X(X())
@0x499602D2嘿,我甚至链接到一个页面,解释说:)我将行更改为RSSFeed feed=RSSFeed(it->first);但现在我得到了错误--rss feed.h:In函数–void processallfeed(const string&)–rss feed.h:54:3:error:In–error–RSSFeed::RSSFeed(const RSSFeed&)–is private news aggregator.cc:117:35:error:在这个上下文新闻聚合器中。cc:117:35:error:使用删除的函数–RSSFeed::RSSFeed(const RSSFeed&)–rss-feed.h:54:3:error:在此处声明此问题称为一个
vexing解析
,请参见/***构造函数:RSSFeed*用法:RSSFeed提要(“);*------------------------------------------------------------------------------------------------------------------------*围绕提供的URL构造RSSFeed对象。*/RSSFeed(const std::string&url):url(url){}我不认为这是问题所在,我省略了构造函数的参数,但当我使用feed作为变量时,代码运行良好。@MaxBozzi不,这只是一个麻烦的解析。一个非常烦人的问题