草庐IT

Non-Public

全部标签

c++ - 公共(public)新私有(private)构造函数

当我尝试编译以下内容时:#includeclassTest{public:void*operatornew(size_tnum);voidoperatordelete(void*test);~Test();private:Test();};Test::Test(){std::cout(test));}intmain(){Test*test=newTest;deletetest;}我明白了:$g++-otesttest.cpptest.cpp:Infunction‘intmain()’:test.cpp:14:error:‘Test::Test()’isprivatetest.cpp:3

c++ - 在 public 中使用 "using"继承 private 构造函数并没有使其 public

“使用”私有(private)成员变量使其成为公共(public)成员,但构造函数保持私有(private)。示例:classMyClass;classBase{private:Base(floatv):m_v{v}{}floatm_v;friendMyClass;};classMyClass:publicBase{public:usingSuper=Base;usingSuper::Super;//thisisstillprivateusingSuper::m_v;//thisispublic};intmain(){MyClassx{3.4f};//error-callingapri

c++ - 为什么 VS 和 gcc 在这里调用不同的转换运算符(const vs non-const)?

这段代码当然很蠢,但我写它只是为了说明问题。在这里:#includeusingnamespacestd;structfoo{inta=42;templateoperatorT*(){cout(&a);}templateoperatorconstT*()const{cout(&a);}templateTget(){coutoperatorT();}};intmain(){foomyFoo;cout()使用VisualStudio2019(ISOC++17,/Ox)编译时的输出是:Tget()operatorconstT*()const42gcc8.3(-std=c++17,-O3)的输出

c++ - 防止同一个类的实例调用公共(public)函数(C++)

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whydoobjectsofthesameclasshaveaccesstoeachother’sprivatedata?我在尝试保持封装时从未理解的东西:假设我有一个名为GameObject的类和一个名为Human的派生类。GameObject有一个私有(private)变量position。我有多个Human实例,我希望每个人都能够调用SetPos()并根据需要设置其位置。然而,我不希望一个人有能力确立另一个人的地位。这是我的问题。如果我有SetPospublic或protected,每个人都可以改变彼此

python - 如何创建一个可以接收 c++ 结构/实例或 python 对象作为参数的公共(public) cython 函数?

我的矩形.hnamespaceshapes{classRectangle{public:intx0,y0,x1,y1;Rectangle();Rectangle(intx0,inty0,intx1,inty1);~Rectangle();intgetArea();};}我的矩形.cpp#include"Rectangle.h"namespaceshapes{Rectangle::Rectangle(){}Rectangle::Rectangle(intX0,intY0,intX1,intY1){x0=X0;y0=Y0;x1=X1;y1=Y1;}Rectangle::~Rectangle

c++ - 将私有(private)函数覆盖到公共(public)函数的潜在危险是什么?

我刚刚发现在C++中允许将私有(private)函数从基对象覆盖为公共(public)函数,因为VisualStudio会产生0警告。这样做有什么潜在的危险吗?如果没有,在基础对象中声明一个私有(private)的、protected和公共(public)的虚函数有什么区别? 最佳答案 what'sthedifferencebetweendeclaringavirtualfunctioninprivate,protectedandpublicinabaseobject?不同之处在于,private虚函数只能从基类中调用。如果该函数不

c++ - 在 boost::python 的类中公开公共(public)结构

我想在带有boost::python的python代码上使用这个C++类/*creature.h*/classHuman{private:public:structemotion{/*Allemotionsarepercentages*/charjoy;chartrust;charfear;charsurprise;charsadness;chardisgust;charanger;charanticipation;charlove;};};问题是如何在boost-python中公开这个公共(public)属性namespacepy=boost::python;BOOST_PYTHON

c++ - 检查非事件 union 成员,公共(public)初始序列

这个问题是基于this考虑以下几点:structHdr{inttype;};structA{Hdrh;};unionBig{Hdrh;Aa;};并假设对于Bigbig我们知道big.a是union体的活跃成员。是否访问big.h.type未定义的行为?我认为确实是UB,基于:class.union...[ Note:Onespecialguaranteeismadeinordertosimplifytheuseofunions:Ifastandard-layoutunioncontainsseveralstandard-layoutstructsthatshareacommoninit

c++ - 添加 Boost 使调试构建依赖于 "non-D"MSVC 运行时 DLL

我有一个烦人的问题,我可能能够以某种方式规避它,但另一方面,我更愿意了解它并了解到底发生了什么,因为看起来这些东西真的会留下来。故事是这样的:我有一个简单的OpenGL应用程序,它运行良好:在编译、链接或运行它时从来都不是主要问题。现在我决定尝试将一些更密集的计算移到工作线程中,以便可能使GUI响应更快——当然是使用Boost.Thread。简而言之,如果我在.cpp文件的开头添加以下片段:#includevoiddummyThreadFun(){while(1);}boost::threadp(dummyThreadFun);,然后我在尝试启动调试版本时开始收到“此应用程序无法启动,

C++, Linux : error: conversion from ‘boost::unique_future<void>’ to non-scalar type ‘boost::shared_future<void>’ requested. 如何绕过它?

我尝试使用boostthreadfutures.所以如图here我们可以得到sharedfuture来自packagedtask.所以我在linux上尝试这样的功能:templatevoidpool_item(boost::shared_ptr>pt){boost::shared_futurefi=pt->get_future();//error//...但调用它时出错:../../src/cf-util/thread_pool.h:Inmemberfunction‘voidthread_pool::pool_item(boost::shared_ptr>)[withtask_retu