gpt4 book ai didi

c++ - 模板函数只适用于 VS

转载 作者:行者123 更新时间:2023-11-30 01:33:13 25 4
gpt4 key购买 nike

<分区>

我用模板编写了代码,但它只适用于 Visual Studio(不适用于 Dev c++ 或任何在线编译器。我不明白为什么。

#include <iostream>
using namespace std;

template <class Q1,class Q2,class Q3> // but when i write instead of 3 classes 1 class it will work
//everywhere, how could it be possible?

void min(Q1 a, Q2 b, Q3 c) {
if (a <= b && a <= c) {
cout << "\nMinimum number is: " << a << endl; }
if (b < a && b < c) {
cout << "\nMinimum number is: " << b << endl; }
if (c < a && c < b) {
cout << "\nMinimum number is: " << c << endl; }

}

int main()
{

double x,y,z;
cout << "Enter 3 numbers: " << endl;
cin >> x;
cin >> y;
cin >> z;

min(x, y, z);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com