草庐IT

more-private

全部标签

c++ - 在 LGPL 下的商业产品中使用 Qt 时如何允许私有(private)修改

我正在考虑构建一个动态链接到Qt库的闭源应用程序。目标平台将是Linux和Windows。为了履行LGPL的义务:"Theuserofyourapplicationhastobeabletore-linkyourapplicationagainstadifferentormodifiedversionoftheQtlibrary"(Qtfaq).我正在努力理解实现此目标的技术必要条件。尤其是在不发布源代码的情况下。在什么情况下,用户可以只用自己的修改版本替换应用程序附带的.so/.dll文件?这可能吗?因为在同样的事情上libstdc++faq状态:TheLGPLrequirestha

c++ - 检查类是否具有 typedef(私有(private)或其他)的特征

有没有办法检查class有一个typedef这甚至适用于privatetypedef?以下代码在VS2013中有效,但在ideone'sgcc上失败templatestructto_void{typedefvoidtype;};classFoo{typedefintTD;};templatestructhas_TD:std::false_type{};templatestructhas_TD::type>:std::true_type{};intmain(){std::cout::value编辑-我为什么要这个我有自定义序列化系统,可以序列化任意类型。当它必须表现不同时(例如字符串),

c++ - header 中的 private static const 成员变量与 cpp 中的 const 变量

为什么我应该在header中声明一个私有(private)的staticconst变量(并在cpp中初始化它)而不是仅仅在cpp中定义+声明它?即案例1.hclassMyClass{...private:staticconstMyTypesome_constant;}case1.cppconstMyTypeMyClass::some_constant=...;案例2.h//Nomentionofsome_constantatall案例2.cppconstMyTypesome_constant=...;假设遵循常见的c++约定(1个header和cpp仅与1个类相关联,从不与#inclu

c++ - 私有(private)函数作为其他类的 friend

我有以下用C++编写的代码:#includeusingnamespacestd;classWindow;classLevel{intlevel;intget(Window&w);public:Level(void):level(3){}voidshow(Window&w);};voidLevel::show(Window&w){cout我想访问类Window的私有(private)成员,只能通过友元函数get访问,这也是类Level的私有(private)函数.当我尝试编译时出现错误C2248。是否可以将私有(private)函数设为其他类的友元? 最佳答案

c++ - 为什么这段代码会出现 "exception spec is more lax than base"错误?

尝试使用Xcode6.1中的clang版本(基于LLVM3.5svn的clang-600.0.54)编译以下代码,使用-std=c++11和-stdlib=libc++给我一些我不太明白的错误。#includestructImpl{typedefstd::functionL;Ll;inti;};structHndl{Impl*impl;Hndl(Impl*i):impl(i){}~Hndl()noexcept(false){}};intmain(intargc,char*argv[]){Hndlh(newImpl());h.impl->l=[=]{h.impl->i=42;};retu

c++ - 使用 pimpl 习惯用法时如何创建私有(private)静态常量字符串

背景我一直在学习如何使用HerbSutter在本页描述的更新的c++11方法来实现pimpl习语:https://herbsutter.com/gotw/_100/我试图通过向私有(private)实现添加成员变量来修改此示例,特别是std::string(尽管char*具有相同的问题)。问题由于使用了staticconst非整数类型,这似乎是不可能的。只能对整数类型进行类内初始化,但由于它是静态的,因此也不能在构造函数中进行初始化。解决这个问题的方法是在头文件中声明私有(private)变量,并在实现中对其进行初始化,如下所示:C++staticconstantstring(clas

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++ - 无法访问类中声明的私有(private)成员 'QReadWriteLock' 错误 1 ​​错误 C2248 : 'QReadWriteLock::QReadWriteLock'

这真的感觉像是Qt中的一个错误。任何人都有解决方案或我应该将其作为错误提交吗?#includeclassFileInfoWrapper{public:explicitFileInfoWrapper(constQFileInfo&_fileInfo);~FileInfoWrapper();private://alsotriedpublicmutableQReadWriteLocklock_;甚至在使用它之前,我得到了错误:Error1errorC2248:'QReadWriteLock::QReadWriteLock':cannotaccessprivatememberdeclaredi

c++ - 类中的几个 "private"声明

我正在查看一些开源代码,发现了这样一个类声明:classFoo{private://declarationsprivate://declarationsprivate://declarationspublic://declarations};除了在非常的声明列表中提醒您成员的隐私外,您是否有任何时候想要做这样的事情? 最佳答案 这对于此类场景特别有用:classSomeClass{//COnstructorsetc.public:SomeClass();SomeClass(constSomeClass&other);~SomeCla

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。