小编use*_*149的帖子

将const对象显式传递给构造函数,该构造函数将const引用到多态类

我遇到了类的问题,将一个const对象(多态结构)传递给一个显式构造函数,该构造函数对该多态结构的基类进行了const引用.这是示例(这不是我的代码,这里是解释)

class Base 
{
...
}

class Derived:public Base
{
...
}

class Problem 
{
    Problem(const Base&);
...
}

void myFunction(const Problem& problem) 
{
    ...
}

int main() 
{
    //explicit constructor with non const object
    Derived d;
    Problem no1(d); //this is working fine 
    myFunction(no1);

    //implicit constructor with const object
    Problem no2=Derived(); //this is working fine, debugged and everything called fine
    myFunction(no2);   //is working fine

    //explicit constructor with const object NOT WORKING
    Problem no3(Derived());  //debugger jumps over this line (no compiler …
Run Code Online (Sandbox Code Playgroud)

c++ constructor explicit

2
推荐指数
1
解决办法
682
查看次数

如何模拟GL_DEPTH_CLAMP_NV?

我有一个没有此扩展程序的平台(非NVIDIA).我怎么能模仿这个功能?我需要它来解决使用z-fail算法渲染模板阴影卷时的远平面剪裁问题.

shader opengl-es depth

1
推荐指数
1
解决办法
2070
查看次数

标签 统计

c++ ×1

constructor ×1

depth ×1

explicit ×1

opengl-es ×1

shader ×1