草庐IT

protected

全部标签

c++ - C++继承中的protected和private成员变量

我是C++的新手,我有一个关于继承中的c++protected和private成员的问题。如果一个类是public继承了一个基类,protected和private成员变量是否会成为派生类的一部分?例如:classBase{protected:inta;intb;private:intc;intd;public;intq;};classDerived:publicBase{};类Derived是否也有a,b,c,d,q的所有成员?我们可以在Derived类中将inta定义为public、protected和private吗? 最佳答案

C++ API : license management to protect a software

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭7年前。Improvethisquestion我正在寻找一个C++和开源库来保护商业软件再次破解等...你认识一个吗?

c++ - protected 数据成员和数据函数

当我在一个类中声明一个protected数据成员时,这意味着它不能被外部世界访问,只能被派生类访问。我的问题是willitbeaccesibletoaclassthatisderivedfromthederivedclass? 最佳答案 是的,protected数据成员在继承层次结构中一直是可访问的。通常最好避免使用protected数据。另一种方法是编写访问私有(private)数据的protected方法。这使数据封装在一个类中。它还可以轻松地为数据更改设置断点。 关于c++-pro

c++ - 我应该公开 protected std::vector 吗?

我有一个类,我打算让其他人继承。它有一个std::vector,我只希望开发人员能够读取它,但不能修改它,我的基本函数会修改它。我应该提供一个返回const迭代器的函数,还是将vector公开为protected。谢谢 最佳答案 如果将vector公开为protected,子类将能够修改它。因此,您应该公开返回const迭代器的方法。您可以使用Non-VirtualInterfaceidiom为用户和子类公开不同的接口(interface)。 关于c++-我应该公开protectedst

c++ - 如何访问派生类中的 protected 成员?

来自http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html#faq-19.5Amember(eitherdatamemberormemberfunction)declaredinaprotectedsectionofaclasscanonlybeaccessedbymemberfunctionsandfriendsofthatclass,andbymemberfunctionsandfriendsofderivedclasses那么,如何访问派生类中的protected函数fun呢?#includeusingna

c++ - protected 析构函数的基本原理

我注意到许多Poco类都有一个protected析构函数。这让他们编码起来更烦人。例如,这是我的一些代码:structW2:Poco::Util::WinRegistryConfiguration{typedefPoco::Util::WinRegistryConfigurationinherited;usinginherited::inherited;};std::stringget_documents_folder(){W2regc{"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\

c++ - 在扩展派生自的模板之前访问模板的基类

我正在尝试从模板中公开派生一个类,这将使它从基类继承并获得对protected成员的访问权限。但是在模板展开之前它没有这些权限,所以它不能使用Base成员作为模板参数:usingFun=void(*)();classBase{protected://friendclassDerived;//...needthistoeliminatecomplaintstaticvoidsomething();};templateclassVariant:publicBase{};classDerived:publicVariant{//`something()`isprotectedpublic:v

c++ - 关于来自 VC12 和 VC14 的 c++ 友元和继承的不同行为

classBase{protected:voidfunc1();};classDerived:publicBase{friendclassThird;};classThird{voidfoo(){Derived;d.func1();}};我可以在VC14(VisualStudio2015)中编译代码而不会出错但从VC12(VisualStudio2013)得到错误cannotaccessprotectedmemberdeclaredinclass'Base'谁是对的?这种具有继承性的友元的正确性是什么?来自MSDNhttps://msdn.microsoft.com/en-us/lib

c++ - 为什么成员函数尝试 block 处理程序中的 lambda(捕获 'this')不能访问 VC++ 2013 中的私有(private)数据成员?

与thisquestionaboutstaticinitializers不同但可能相关.前两个函数编译良好,最后一个函数在vc++中不编译,但在clang和gcc中编译:classA{protected:std::stringprotected_member="yay";public:voidwithNormalBlock();voidwithFunctionBlock();voidnoLambda();};voidA::withNormalBlock(){try{throwstd::exception();}catch(...){[this](){std::coutinclang(好

c++ - 将其中一个继承的 protected 成员设为私有(private)

classA{protected:intm_a;intm_b;};classB:publicA{};在B类中,我想将m_a设为私有(private)。下面的做法是否正确classB:publicA{private:intm_a;};这不会产生2个m_a拷贝吗? 最佳答案 调整成员访问控制的正确方法是使用usingdeclaration:classB:publicA{private:usingA::m_a;}只写intm_a;确实会导致m_a的两个拷贝,并且派生类将能够访问A的通过编写A::m_a复制m_a。