草庐IT

declarative-services

全部标签

c++ - 在 C++ 中 : why does a constructor get called when an array of objects is declared?

MyClassmc2[]={MyClass(),MyClass()};//thiscallstheconstructortwiceMyClassmc1[4];//thiscallstheconstructor4times.Why?所以,我的问题是:为什么没有初始化的对象数组声明会导致调用默认构造函数? 最佳答案 在C++中,大小为4的MyClass数组是四个实际对象。它有点像包含该类型的四个成员的结构,当然您可以使用不同的语法访问这些成员,并且存在其他技术差异。因此,定义该数组导致构建4个对象的原因(并且在大致相同的情况下)与定义该

C++ 错误 : definition of implicitly-declared

我正在用C++编写这个链表程序当我测试程序时,我得到了错误linkedlist.cpp:5:24:error:definitionofimplicitly-declared'constexprLinkedList::LinkedList()'LinkedList::LinkedList(){这是代码链表.h文件:#include"node.h"usingnamespacestd;classLinkedList{Node*head=nullptr;intlength=0;public:voidadd(int);boolremove(int);intfind(int);intcount(i

c++ - C++模板函数中,依赖函数调用为什么报 "not declared"错误?

在C++模板函数foo()中,调用::bar(TT*)在gcc4.4.3下会出现以下错误:g++-ohello.o-c-ghello.cpphello.cpp:Infunction'voidfoo(std::vector>&)':hello.cpp:8:error:'::bar'hasnotbeendeclared这是有问题的代码://hello.cpp#includetemplatevoidfoo(std::vector&vec){TT*tt;::bar(tt);vec.push_back(tt);}classBlah{};voidbar(Blah*&){}intmain(intar

c++ - 错误 C2248 : 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

我无法理解这个错误。这个错误不在我正在调试的类中。(是吗?)错误是:c:\programfiles\microsoftvisualstudio10.0\vc\include\fstream(890):errorC2248:'std::basic_ios::basic_ios':cannotaccessprivatememberdeclaredinclass'std::basic_ios'1>with1>[1>_Elem=char,1>_Traits=std::char_traits1>]1>c:\programfiles\microsoftvisualstudio10.0\vc\inc

c++ - boost::asio::io_service 就绪处理程序的定义是什么?

我试图了解io_service的poll()/poll_one()和run()/run_one()之间的区别。文档中所述的区别在于poll()执行就绪处理程序,而不是执行任何处理程序的run()。但是我在boost文档中的任何地方都找不到“就绪处理程序”的定义。这个问题的有效答案是能够显示(最好是通过代码示例)就绪处理程序和未就绪处理程序之间的区别以及poll()和run()执行它的方式之间的区别。谢谢。 最佳答案 “就绪处理程序”是准备好执行的处理程序。如果您发出了一个异步调用,它会在后台执行,并且它的处理程序在异步调用完成后准备

C++11 decltype : How to declare the type that a pointer points to?

我有以下代码:#includeintmain(){int*a=newint(2);std::unique_ptrp(a);}导致这些错误信息:Infileincludedfroma.cpp:1:Infileincludedfrom/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/memory:81:/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/

c++ - GCC 编译错误 : declaration of ‘strlen’ must be available

我的问题是,当我想制作一个下载的库时,我从GCC得到了一些奇怪的编译错误。编译器要求更正的代码似乎是正确的。报错都是这样的:Catalogue.h:96:error:therearenoargumentsto‘strlen’thatdependonatemplateparameter,soadeclarationof‘strlen’mustbeavailable这是第96行附近的代码:GaCatalogueEntry(constchar*name,T*data){if(name){_nameLength=(int)strlen(name);//LINE96//copyname_name

C++ 风格约定 : Parameter Names within Class Declaration

我是一个相当新的C++程序员,我想听听支持和反对在类声明中命名参数的争论。这是一个例子:Student.h#ifndefSTUDENT_H_#defineSTUDENT_H_#includeusingnamespacestd;classStudent{private:stringname;unsignedintage;floatheight,GPA;public:Student(string,unsignedint,float,float);voidsetAge(unsignedint);};#endif/*STUDENT_H_*/对比#ifndefSTUDENT_H_#defineS

c++ - 使用数组作为元组成员 : Valid C++11 tuple declaration?

下面的代码可以在G++4.7.2中正常编译:#includestd::tuplex;但是,使用clang++3.2会产生以下错误:错误:数组初始化器必须是一个初始化器列表。如果我从元组声明中删除float类型,错误就会消失。上面的元组声明是否有效?($CXX-std=c++11-c文件.cpp) 最佳答案 我认为标准中没有任何内容禁止您的声明。但是,一旦尝试初始化、复制、移动或分配元组,就会遇到问题,因为对于这些操作,元组的所有成员类型都必须能够用作初始化器、可复制构造、可复制分配和移动分配,分别(§20.4.2.1)。这些都不是数

c++ - 在动态加载的库之间共享一个 boost::asio::io_service 对象

首先我做了什么(如果不仅仅是我在做一些愚蠢的事情,将提供最少的样本):我有一个GUI应用程序,它应该支持多个网络接口(interface)来更改GUI中显示的内容。网络接口(interface)实现为在GUI启动时动态加载的插件。GUI应用程序提供了一个boost::asio::io_service对象,它通过对接口(interface)的引用传递该对象,以便它们可以使用它来构建异步I/O。在GUI线程中,轮询此io_service对象以同步网络接口(interface)对内容的访问。现在的问题是处理程序在轮询时不会被io_service对象调用。为了缩小这个范围,我只实现了一个接口(