Inexplicable C + + errors

光辉 韦 41 Reputation points
2021-01-31T10:25:28.087+00:00

The code is as follows:

include<iostream>

include<cmath>

using namespace std;
template<class T, class A, class...Q>
class Math {
public:
Math() {};
Math(T t, A a, Q...q) {
if (t > a)
{
l[index] = t;
l[index + 1] = a;
};

};
template<class V>
auto guide(string* p, V v) {
    auto i = v;
    switch (p)
    {
    case "cos":
        i = cos(v);
        break;
    case "sin":
        i = sin(v);
    case "sqrt":
        i = sqrt(v);
        break;
    case "tan":
        i = tan(v);
    default:
        return i;
        break;
    };
    return i;
}

int index = 0;

private:
T l[900]=0;
};

int main() {
Math<int, int, int>p(12, 14, 15);

}
//It can't work

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,637 questions
0 comments No comments
{count} votes

Accepted answer
  1. David Lowndes 4,711 Reputation points
    2021-01-31T10:33:59.933+00:00

    It's generally recommended to be somewhat clearer when you ask a question than "It can't work", but anyhow, try changing the line to:

    T l[900]={0};


0 additional answers

Sort by: Most helpful