如何使类返回其他类型而不用吸气剂?

时间:2018-07-03 09:44:53

标签: c++ class

我的代码:

class MyWindowSettings {

public:

    const ofGLFWWindowSettings& get(){
        return settings;
    }

private:
    ofGLFWWindowSettings settings;
};

如何将此类用于需要ofGLFWWindowSettings而不是MyWindowSettings且没有吸气剂的函数?

目前我知道

MyWindowSettings settings;
ofCreateWindow(settings.get());

但是我想代替以下内容

MyWindowSettings settings;
ofCreateWindow(settings);

我该怎么做?

1 个答案:

答案 0 :(得分:4)

您可能要做的是使用user-defined convertion运算符

class MyWindowSettings {

public:

    operator const ofGLFWWindowSettings&(){
        return settings;
    }

private:
    ofGLFWWindowSettings settings;
};