首页 > 解决方案 > 将参数传递给 c++ 11 中的结构

问题描述

一个新手问题,但是如何在 c++ 11 中将参数传递给 struct。我一直在使用 c++ 14 这个方法有效。今天我被迫使用 c++ 11,我被这个错误困住了;

error: no matching function for call to 'infinity::infinity(<brace-enclosed 
initializer list>)'return infinity{(x1 == x2), s};

我的代码:

struct infinity{
    bool yes = false;
    float m = 0;
};

infinity slope(float x1, float y1, float x2, float y2){
    float s = (y2-y1)/(x2-x1);
    return infinity{(x1 == x2), s};
}

谢谢!

标签: c++c++11structargumentsc++14

解决方案


推荐阅读