草庐IT

reference_name

全部标签

c++ - 数组 : Storing Objects or References

作为一名Java开发人员,我有以下C++问题。如果我有类型A的对象并且我想将它们的集合存储在一个数组中,那么我应该只存储指向对象的指针还是存储对象本身更好?在我看来,存储指针更好,因为:1)通过将对象的指针设置为null,可以很容易地删除对象2)节省空间。 最佳答案 指针还是对象?在C++中不能将引用放在数组中。您可以制作一个指针数组,但我仍然更喜欢容器和实际对象而不是指针,因为:没有机会泄漏,异常安全更容易处理。它并没有减少空间——如果你存储一个指针数组,你需要对象的内存加上指针的内存。我唯一提倡将指针(或智能指针会更好)放入容器

c++ - 如何在编译时检测 C++ 中的 std::reference_wrapper

假设我们有一些可变参数模板,需要以不同方式处理std::reference_wrapper参数。我们怎样才能做到这一点? 最佳答案 你可以做一个特征来判断一个类型是否是reference_wrappertemplatestructis_reference_wrapper:false_type{};templatestructis_reference_wrapper>:true_type{};然后你可以用它来消除歧义:templatevoiddo_stuff(T&&t,false_type){coutvoiddo_stuff(T&&r

vscode打开Python项目 ModuleNotFoundError: No module named

方法1、cmd+shift+p,选择openusersettings"terminal.integrated.env.osx":{"PYTHONPATH":"${workspaceFolder}/",},"terminal.integrated.env.linux":{"PYTHONPATH":"${workspaceFolder}/",},"terminal.integrated.env.windows":{"PYTHONPATH":"${workspaceFolder}/",},这段配置在VSCode中起到了设置Python运行环境的作用。具体来说,它设置了在不同操作系统下集成终端的环境变

c++ - 枚举 "does not name a type' 的问题

g++(Ubuntu/Linaro4.4.4-14ubuntu5)4.4.5我有一个问题,我似乎找到了我得到这个错误的方法。文件statemachine.h#ifndefSTATEMACHINE_H_INCLUDED#defineSTATEMACHINE_H_INCLUDED#include"port.h"enumstate{ST_UNINITIALIZED=0x01,ST_INITIALIZED=0x02,ST_OPENED=0x03,ST_UNBLOCKED=0x04,ST_DISPOSED=0x05};voidstate_machine(eventevt,port_t*port)

c++ - undefined reference 和非虚拟 thunk

这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭9年前。我有这样的类(class):classProduct{public:virtualdoublegetPrice();virtualvoidsetPrice(doubleprice);};classMusicProduct{protected:stringauthor;doubleprice;public:virtualstringgetAuthor();v

c++ - 对 B::B & B::~B 的 undefined reference

我不断收到g++编译器的投诉,说下面的代码有问题。仔细检查后,我还是想不通为什么从embedMain.cpp中找不到B类的构造函数和析构函数。谁能给我一点提示?谢谢//embedMain.cpp#include"embed.h"intmain(void){Bb("helloworld");return0;},//embed.h#ifndefEMBED_H#defineEMBED_H#includeclassB{public:B(conststd::string&_name);~B();private:std::stringname;};#endif,//embed.cpp#includ

c++ - 错误 : ‘i’ does not name a type with auto

这个问题在这里已经有了答案:HowdoIenableC++11ingcc?(4个答案)关闭7年前。我是C++新手,这是我的程序#include#include#include#include#includeintmain(){staticconstdoublearr[]={16.0,2.2,77.5,29.0,24.0};std::vectorvec(arr,arr+sizeof(arr)/sizeof(arr[0]));std::transform(vec.begin(),vec.end(),vec.begin(),bind2nd(std::minus(),3.0));for(aut

c++ - 错误 : '...' does not name a type

我有一个工作项目。重新安排一些代码后,我尝试重新编译我的项目,然后奇怪的事情开始发生。查看编译器输出的这段摘录。我正在使用MinGWG++从Windows上的Eclipse进行编译。****BuildofconfigurationDebugforprojectPract2********InternalBuilderisusedforbuild****g++-O0-g3-Wall-c-fmessage-length=0-omove.o..\move.cppInfileincludedfrom..\/game.h:11:0,from..\/piece.h:10,from..\/move.

c++ - 继承 : expected class-name before ‘{’ token

我试图在C++中创建一个异常类,但它不起作用。我已将代码减少到最少,但仍然找不到错误。这是我的头文件:#ifndefLISTEXCEPTION_H#defineLISTEXCEPTION_H//C++standardlibraries#include/*CLASSDEFINITION*/classListException:publicexception{};#endif//LISTEXCEPTION_H这是我得到的错误:error:expectedclass-namebefore‘{’token这是出乎意料的。我该如何解决这个问题? 最佳答案

C++ 单例 undefined reference

我是C++的新手,正在尝试理解C++中的单例模式。myclass.h#ifndefMYCLASS_H#defineMYCLASS_HclassMyclass{public:staticMyclass*getInstance();private:Myclass(){}Myclass(Myclassconst&){}Myclass&operator=(Myclassconst&){}staticMyclass*m_instance;};#endif//MYCLASS_Hmyclass.cpp#include"myclass.h"Myclass*Myclass::getInstance(){