草庐IT

copy-protection

全部标签

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

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

c++ - 为什么这里调用的是 Copy Constructor 而不是普通的 Constructor 和重载的赋值运算符?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:IsthereadifferenceinC++betweencopyinitializationanddirectinitialization?CopyconstructorsandAssignmentOperators我有一个C类,我在其中重载了Normal、复制构造函数和赋值运算符以打印被调用内容的踪迹。我写了以下代码来测试什么时候被调用?Cc1;-->NormalConstuctor..//understoodFineCc2;c2=c1;-->Normalconstructor+assignmentop

c++ - copy-and-swap 技术在赋值运算符函数中使用复制构造函数

我正在阅读“EffectiveC++byScottMeyers”,其中第11项建议在我的赋值运算符中使用“copy-and-swap”技术:Widget&Widget::operator=(constWidget&rhs){Widgettemp(rhs);//Copyconstructorswap(temp);//Swapwith*thisreturn*this;}但是在Item12中是这样写的:Itmakesnosensetohavecopyassignmentoperatorcallthecopyconstructor.我认为第11项和第12项是矛盾的。我理解错了吗?

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# - 无法在我的 WPF 应用程序中使用 Array.Copy()

我是一名C++开发人员,最近开始从事WPF方面的工作。好吧,我在我的应用程序中使用Array.Copy(),看起来我无法完全获得所需的结果。我在我的C++应用程序中做了如下操作:staticconstsignedcharversion[40]={'A','U','D','I','E','N','C','E',//name0,0,0,0,0,0,0,0,//reserved,firmwaresize0,0,0,0,0,0,0,0,//boardnumber0,0,0,0,0,0,0,0,//variant,version,serial0,0,0,0,0,0,0,0//datecode,r

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。

c++ - 具有基于 protected 基类方法的返回类型的函数

我试图让doSomeMethod()的返回类型与operator()相同在基类中,但如果它被声明为protected,编译器将拒绝带有error:notypenamed'type'in'std::result_of'的代码.如果它是公开的,它就可以工作,但我想知道从那以后我是否也可以让它为protected案例工作。这是重现错误的简单代码。#includeclassbase{protected:intoperator()(){return1;};};classchild:privatebase{autostaticdoSomeMethod()->typenamestd::result_

C++ 保护 : fail to access base's protected member from within derived class

不可否认,这个问题的标题听起来与你的邻居迈克反复问的问题几乎一模一样。我发现很多问题的措辞相同,但没有一个是我的问题。首先,对于这个问题的上下文,我想澄清几点:1,c++访问控制是基于类而不是基于实例。因此,下面的代码是完全有效的。classBase{protected:intb_;public:boolIsEqual(constBase&another)const{returnanother.b_==b_;//accessanotherinstance'sprotectedmember}};2,我完全理解为什么以下代码无效-另一个可以是兄弟实例。classDerived:public

c++ - 为什么派生类不能通过指向基类的指针访问其基类的 protected 成员?

这是code:classTestA{protected:inttest=12;public:TestA(){couttest;}~TestB(){}};intmain(){TestA*pTestA=newTestA();TestB*pTestB=newTestB(pTestA);}我正在尝试使用指向TestA类型对象的指针访问protected成员(因此,TestA的实例).TestB也派生自TestA为什么我无法访问它?它只能在我需要它的类(class)“内部”访问吗?不在外部使用指针/直接声明? 最佳答案 当public继承自基

c++ - 对于具有抛出复制构造函数和 noexcept 按值复制赋值的类,is_nothrow_copy_assignable 的值是多少?

根据C++标准,以下程序的预期(如果有)输出是什么:#include#include#includeclassA{public:A()=default;~A()=default;A(Aconst&other){}A(A&&other)noexcept{}A&operator=(Aother)noexcept{return*this;}};intmain(){std::cout::value::value换句话说,类型特征值的评估是否只看赋值运算符的声明,即noexcept,并因此产生truetrue或者它是否考虑调用上下文(a、b是A的实例)a=b;//maythrow,implici