小编aws*_*r27的帖子

"错误:没有匹配的函数来调用"

我在键盘上,我正在尝试使用C++建立自己的技能.我之前从未使用过模板,所以我试着研究如何使用它们.下面的代码是结果,不幸的是,它不起作用.我确实试图寻找我的问题的解决方案,但由于我没有使用模板的经验,我无法在我的问题和其他问题之间建立任何联系.所以,我决定寻求帮助.

template <class A>
class Vector2 {
public:
    A x,y;
    Vector2(A xp, A yp){
        this->x = xp;
        this->y = yp;
    }
};

template <class B, class A>
class rayToCast {
public:
    rayToCast(B angle, Vector2<A> origin, Vector2<A> point1, Vector2<A> point2){
        this->RAngle = angle;
        this->Point1 = point1;
        this->Point2 = point2;
    }
private:
    B RAngle;
    Vector2<A> point1,point2;
};

int main(){
    rayToCast<short int, float> ray(45, Vector2<float>(0.0, 0.0), Vector2<float>(-10.0, -3.0), Vector2<float>(5.0, 7.0));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是输出:

t.cpp: In constructor 'rayToCast<B, A>::rayToCast(B, Vector2<A>, Vector2<A>, Vector2<A>) [with …
Run Code Online (Sandbox Code Playgroud)

c++ templates constructor

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

标签 统计

c++ ×1

constructor ×1

templates ×1