草庐IT

scope1_method

全部标签

C++ 嵌套模板 : inaccessible static method

我在以下代码中遇到了一个奇怪的(或者可能不是)错误:templateclassRegistrer{public:Registrer(){Registry::register(T::instance);}};templateclassRegisteringClass{private:staticconstRegistrerREGISTRER;public:RegisteringClass(){Q_UNUSED(REGISTRER);/*forcestaticinstantiation*/}staticconstWhatEver*instance(){staticTINSTANCE;ret

c++ - gdb python编程: how to write code that will set breakpoints to every method of a C++ class?

我希望能够在gdb中为C++类的每个方法设置断点。我认为最简单的方法可能是python,因为现在python可以完全访问gdb。我对python知之甚少,而在它上面加上gdb,它就更难了。我想知道是否有人知道如何编写一个类python代码来为gdb中命名类的每个方法设置断点。 最佳答案 假设您使用调试符号进行编译,您甚至不需要python:rbreaksource.cpp:. 关于c++-gdbpython编程:howtowritecodethatwillsetbreakpointsto

c++ - 错误 : ‘Class’ was not declared in this scope

请问,如何在另一个类中定义类。在下面的代码中。我尝试以#define"CCompField.h"的方式定义它,但它不起作用。:(。我认为这是非常常见的编程问题,可能在互联网上已经解决了100000次,但我不知道如何找到它。感谢您的帮助。#ifndefCNEWGAME_H#defineCNEWGAME_HclassCNewGame{public:CNewGame();~CNewGame();voidBeginnerGame();voidIntermediateGame();voidAdviceGame();voidHowToPlay();voidNetGame(intmode);intM

c++ - 谷歌测试 Gtest.cc :812: error: 'gettimeofday' was not declared in this scope

我正在尝试通过命令行通过MinGW编译Google测试,但是当我尝试使用命令进行编译时gcc-ID:\gtest-ID:\gtest\include-ID:\gtest\include\gtestsrc\gtest_main.ccsrc\gtest-all.cc它抛出错误Gtest.cc:812:错误:'gettimeofday'未在此范围内声明我通过VisualStudio成功编译,所以我猜这不是代码的错误。还有其他人遇到过这个问题并且知道解决方案吗? 最佳答案 and是两个不同的包含

c++ - 错误 : 'object' was not declared in this scope

我是C++的新手,正在尝试制作大富翁游戏。不幸的是,它仍然显示两个类之间的声明错误。我已经尝试了所有方法,但真的不知道问题出在哪里。错误:“玩家”未在此范围内声明。引擎.h#ifndefENGINE_H#defineENGINE_H#include"Player.h"#includeusingnamespacestd;classEngine{public:Engine();//methodthatstartswithgame,takerandomnumberforgettingnumberofplayers,setplayerstovectorvoidplay();//methodwh

C++ 摆脱单例 : alternative to functors and static methods

我崇高的追求是摆脱单例和静态类。背景:我有以下结构:Cmd经常实例化的对象,它保存命令的名称(字符串),以及任何类的静态方法的仿函数作为指针。它通常在主类中创建,例如Input、Console、Render等,并引用创建它的类中的方法,为这些方法提供运行时口头接口(interface)。Cmds还以字符串数组的形式解释参数,其中第一个参数是Cmd的名称,所有连续的字符串都是被调用的静态方法的直接参数。参数计数和参数数组存储在Commander中,并在每次Cmd调用之前更改。CommanderCommander用于解释字符串命令(可能直接或通过控制台),并执行以字符串形式存储在缓冲区中的

c++ - 当非限定名称查找涉及 using-directives 时 [basic.scope.hiding]p2 的解释

在c++中有两种隐藏的名字:1)普通名称隐藏:[basic.scope.hiding]p1(http://eel.is/c++draft/basic.scope.hiding#1):Anamecanbehiddenbyanexplicitdeclarationofthatsamenameinanesteddeclarativeregionorderivedclass([class.member.lookup]).2)隐藏在[basic.scope.hiding]p2(http://eel.is/c++draft/basic.scope.hiding#2)中的特殊名称类型:Aclassn

c++ - 在 boost::python 中公开 boost::scoped_ptr

我收到一个编译错误,说scoped_ptr的复制构造函数是私有(private)的,代码片段如下:classa{};structs{boost::scoped_ptrp;};BOOST_PYTHON_MODULE(module){class_("s");}虽然这个例子适用于shared_ptr。如果有人知道答案,那就太好了。谢谢 最佳答案 boost::scoped_ptr的语义禁止复制,而shared_ptr旨在被复制。您得到的错误是编译器告诉您某些代码(宏扩展?)正在尝试复制scoped_ptr但库不允许进行复制。

c++ - "gets() was not declared in this scope"错误

这个问题在这里已经有了答案:whyg++shows"gets()"notdeclared,evenafterincluding(3个答案)关闭2年前。使用以下代码,我得到“gets()未在此范围内声明”错误:#include#includeusingnamespacestd;intmain(){//stringstr[]={"Iamaboy"};stringstr[20];`gets(str);cout

c++ - 在顶层使用 shared_ptr 而不是 scoped_ptr 有什么优势吗?

我的团队对于指针容器在特定上下文中的使用存在一些分歧。请考虑:intmain(){//Toplevel.Thisisanimportantfacttothecontext//i.e.thatthefollowinginstanceisatthislevel//sothatitsmembersareessentiallyatprogramscope.MainClassmainClass;mainClass.run();}//AinstanceofaclassderivedfromBufferdoessomethingverycomplex//(ithasvarioushandlestor