I have a class, with a template constructor :
class x
{
public:
template<std::size_t N>
x(int matrix[N][N])
{
std::cout << "template created successfully";
}
};
in main function :
int main()
{
size_t s;
cin >> s;
int m[s][s];
x ob(m); // error
}
the error is:
error: no matching function for call to 'x::x(int [s][s])'|
I want to create an array whose size is given by the user(which it allows) and that same size should be used in the class x.
Why it causes this error and still allow me to create a matrix like this?
What are it's workarounds, since I have to pass array like this to a class?
I'm using codeblock 16.01.
Aucun commentaire:
Enregistrer un commentaire