草庐IT

private_key

全部标签

C++ STL : Why is there no upper_bound equivalent that retrieves the greatest element smaller then a specific key?

通常,STL是为提高速度而构建的。然而,在map和set数据结构上只有upper_bound和lower_bound并且没有操作来检索具有小于输入键的最大键的条目k.为什么是这样?我知道我可以简单地做一个lower_bound并做一个--it检索它,但根据数据结构,立即搜索正确的条目可能比搜索另一个条目然后返回一步更有效。例如,std::map使用红黑树,即二叉搜索树。如果upper_bound返回的元素是大于根的最小元素,则--it必须回到根,查询O(logn)的额外成本。如果这是Java,我会接受设计决定。然而,STL是为实现最高速度而构建的,那么为什么要省略此操作?澄清:我不是在

c++ - 如何使用内联函数说明符将 "hide"私有(private)成员函数?

有一个包含private成员函数的类,我想标记为inline(明确标记我的意图,即特定函数可能被内联),但不要将它们的实现暴露给API使用者。为简单起见,它可能看起来像:飞机.h:classAirplane{charmanufacturer[80];charmode[80];//...public:voidautopilot_steer_left(intdegree);//...private://...inlineboolvalidate_hydraulic_on_left_wing();//secret,patent-based,etc.};飞机.cpp:#include"Airp

C++ 单例用法 : compiler complains about private constructor

我知道有一百万个关于单例的问题和答案,但我似乎无法找到解决方案。所以冒着反对票的风险,这是我的问题:我想使用AndreiAlexandrescu的现代C++设计中的单例实现:标题:classSingleton{staticSingleton&Instance();private:Singleton(){};Singleton(constSingleton&){};Singleton&operator=(constSingleton&){};~Singleton(){};};实现:#include"s.hh"Singleton&Singleton::Instance(){staticSi

c++ - 可以从外部访问私有(private)运营商吗?

即如果我在我的类中的私有(private)部分中定义运算符==和+,它们可以从main访问吗?它在MSVS2008和2010中有效,但对我来说它似乎是编译器中的错误。是这样吗? 最佳答案 在私有(private)访问说明符下声明的函数或成员将无法在类成员函数之外访问。在C++中,类/结构/union有3个访问说明符。这些访问说明符定义了如何访问类的成员。当然,类的任何成员都可以在该类中访问(在同一类的任何成员函数中)。继续访问访问说明符的类型,它们是:Public-声明为Public的成员可通过类的对象从类外部访问。Protecte

c# - 如何在 C# 中使用 Private Inheritance aka C++ 以及为什么它不存在于 C# 中

我知道C++支持私有(private)继承,C#只支持公有继承。我还看到一篇文章说私有(private)继承通常定义类之间的HAS-A关系和某种聚合关系。编辑:私有(private)继承的C++代码:“Carhas-aEngine”关系也可以用私有(private)继承来表达:classEngine{public:Engine(intnumCylinders);voidstart();//StartsthisEngine};classCar:privateEngine{//Carhas-aEnginepublic:Car():Engine(8){}//InitializesthisCa

C++ STL 映射无法识别 key

我有这段代码,CBString只是我用于某些处理的字符串类char*scrummyconfigure::dosub(strtypeinput){CBStringtstring;tstring=input;uintbegin;uintend;begin=tstring.findchr('$');end=tstring.findchr('}',begin);CBStringk=tstring.midstr(begin+2,end-2);//thisisBASEstrtypevname=(strtype)((constunsignedchar*)k);strtypebvar=(strtype

c++ - 为什么这个友元函数不能访问私有(private)变量?

classStudent{public:Student(inttest):key(705){if(test==key){cout>testkey;Studentbob(testkey);printResult();}函数printResult似乎无法从Student类访问私有(private)变量allow。我是在错误的地方制作了printResult原型(prototype)还是语法错误?据我所知,我们可以在类里面的任何地方为friend制作原型(prototype)。 最佳答案 printResult不是成员函数,所以你需要给它

c++ - 非类函数可以私有(private)化吗?

我在我创建的命名空间中有一些函数,这些函数在我的整个程序中都在使用。在头文件中:namespaceNQueens{staticintheur=0;intCalcHeuristic(char**state,intsize);voidCalcHorzH(char**state,int&heuristic,intsize);voidCalcColH(char**state,int&heuristic,intsize);voidCalcDiagH(char**state,int&heuristic,intsize);intcalcCollisions(intqueensPerRow,intsi

c++ - 私有(private)继承和组合,哪个最好,为什么?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭2年前。Improvethisquestion假设我有一个类engin并且我从engin类继承了一个类carclassengin{public:engin(intnobofcylinders);voidstart();};classcar:privateengin{public:car():e(8){}voidstart(){e.start();}private:engine;};现在同样可以通过组合来完成,问题是哪种方法最好并且主要

c++ - 是否可以为const操作指定一个private成员变量public?

我有一个成员变量enabled_m,它的值取决于许多变量。由于这些不变量应该由类维护,我希望它是private:classfoo_t{public:voidset_this(...);//mayaffectenabled_mvoidset_that(...);//mayaffectenabled_mvoidset_the_other_thing(...);//mayaffectenabled_mboolis_enabled()const{returnenabled_m;}private:boolenabled_m;};这行得通,但实际上我的意图是要求foo_t的用户通过该类来修改ena