草庐IT

creating-virtual-environments

全部标签

c++ - 在 Cygwin 中处理 "C compiler cannot create executables"

无论我尝试在Cygwin中编译什么,我都会得到以下输出:checkingformingw32environment...nocheckingforEMXOS/2environment...nocheckinghowtoruntheCpreprocessor...gcc-Echeckingforgcc...gcccheckingwhethertheCcompiler(gcc)works...noconfigure:error:installationorconfigurationproblem:Ccompilercannotcreateexecutables.日志文件的最后几行如下所示:

C++ 重载 virtual = 运算符

这是我的问题的代码:classICommon{public:virtualICommon&operator=(constICommon&p)const=0;};classCSpecial:publicICommon{public:CSpecial&operator=(constCSpecial&cs)const{//customoperationsreturn*this;}};CSpecialobj;基本上:我希望接口(interface)ICommon强制其后代实现=运算符,但不希望在实现中有任何类型转换。编译器说“无法实例化抽象类。任何帮助/建议将不胜感激。

c++ - timer_create 给出内存泄漏问题 "Syscall param timer_create(evp) points to uninitialised byte(s)"

structsigeventtimerEvent;memset(&timerEvent,0,sizeof(timerEvent));timerEvent.sigev_value.sival_int=0;timerEvent.sigev_value.sival_ptr=diaBase;timerEvent.sigev_notify=SIGEV_THREAD;timerEvent._sigev_un._sigev_thread._function=function;timerEvent._sigev_un._sigev_thread._attribute=NULL;timer_ttimer

c++ - 'non-virtual interface' 和 'abstract interface' 有什么区别?

我正在用C++实现设计模式,我希望我的类通过组合来利用接口(interface),这让我研究了实现接口(interface)的不同方法。我想澄清一下这个术语的定义。 最佳答案 非虚拟接口(interface)是一个公共(public)成员函数,它不是虚拟的,但通常希望根据可覆盖的虚拟函数来实现:classInterface{public:intcompute(){returncompute_impl();}private:virtualintcompute_impl()=0;protected:virtual~Interface()

c++ - 如果没有类重新实现 'virtual' 关键字是否可以优化掉?

当我在C++中定义一个类时,我总是将dtor定义为虚拟的。这是我在编写继承类时保护自己的方法。我想知道我是否要支付性能开销,即使我不会继承该类。例如:classAfinal{A();virtual~A(){printf("dtor");}};当我使用这个类时,dtor实际上是通过vtable调用还是作为静态dtor实现? 最佳答案 WhenIdefineaclassinC++Ialwaysdefinethedtorasvirtual.这是非常糟糕的做法。类应该被设计成多态的……或者不是。这也不仅仅是设计问题——多态性增加了开销。现在

c++ - 为什么必须将 "virtual"放入基类而不是仅在子类中使用 "override"?在 C++ 中

标题几乎说明了一切。为什么要在基类中定义以后可能重写的函数?如果您想从中派生出不同行为的版本,那么您必须修改基类,并且您还没有考虑过将基类中的特定函数标记为虚拟。据我所知,您通过使用override解决了java中的此类抽象定义,这对我来说似乎更自然(尽管到目前为止我只关注java)。c++中的这种扭曲是为了强制程序员提前思考,还是有技术原因导致它这样工作? 最佳答案 这样做是为了使成员函数成为虚函数的决定保留在基类中。决定将一个函数设为虚函数会对设计产生影响:如果你将一个函数设为虚函数,你必须考虑它执行不同操作的可能性。相反,您可

c++ - 为什么我需要从主线程使用 `pthread_exit()`,而它不是由 `pthread_create` 创建的?

我对一些正在测试以开始理解posix线程的代码有疑问。我有这个基本代码:#include#include#include#includeusingnamespacestd;void*printInfo(void*thid){longtid;tid=(long)thid;printf("Hellofromthread%ld.\n",tid);pthread_exit(NULL);}intmain(intargc,charconst*argv[]){intnum=8;pthread_tthreadlist[num];intrc;longt;for(t=0;t非常简单的代码,启动线程并从中打

c++ - 语法糖 : automatically creating simple function objects

我要实现一组类模板和两个特殊变量,_1和_2.他们应该使以下内容成为合法代码://Sortascendingstd::sort(a,a+5,_1>_2);//Outputtoastreamstd::for_each(a,a+5,std::cout(std::cout,""),_1+5);我想_1*5也应该产生一个一元函数,以及_1/5等。不允许提升不允许使用lambda现在我有非常对模板和模板元编程的经验很少,所以我什至不知道从哪里开始以及我的类模板的结构应该是什么样子。我特别困惑,因为我不知道在我的类模板中是否必须为所有这些编写实现operator=,operator>>,opera

c++ - "virtual base class in the case of multilevel inheritance"有意义吗

考虑以下显示多级继承的示例代码:案例1:这里类derived1是通过虚拟继承从类base派生的,类derived2是从类派生的直接类derived1。classbase{};classderived1:virtualpublicbase{};classderived2:publicderived1{};Case2:与Case1相同,只是不涉及虚拟继承classbase{};classderived1:publicbase//novirtualinheritance{};classderived2:publicderived1{};假设我在这两种情况下都创建了derived2类的对象。C

C++/QML : How to define and handle multiple contexts for dynamically created components?

基本上我的情况是这样的:我有一个扩展QQuickView的类,它通过设置上下文属性将某些对象从C++公开到QML。显示的View是从QML创建的,并且都是同一定制组件的不同实例;当某些事件发生时会创建新View,当这种情况发生时,现有View应显示最初在C++端分配给它们的对象,而新View应显示分配给它们的对象。所以,在C++方面,我有这样的东西:WindowManager::WindowManager(QQuickView*parent):QQuickView(parent){//Settingthesourcefiletousethis->setSource(QUrl("qrc: