I have a class with template function and a special function, which looks like:
#include <bits/stdc++.h>
using namespace std;
class A {
public:
template <typename T>
void test(const T& t) {
cout << "template " << t << endl;
}
void test(const std::string& s) {
cout << "test " << s << endl;
}
};
int main() {
A a;
a.test("asdas");
}
As you could see, there are two test
function:
template
function- special function which only match
std::string
input.
what i want is:
test(1)
-> calltemplate
functiontest<int>(1)
std::string str = "asd"; test(str);
-> call special functiontest(str)
test("asd")
-> call special functiontest(std::string str = "asd")
how to achieve this?
Aucun commentaire:
Enregistrer un commentaire