Quantcast
Viewing all articles
Browse latest Browse all 4902

C/C++ • Re: Matrix class for C++

Not intended as a criticism, but a genuine question. Why are you deleting the default constructor for class matrix?

Code:

matrix() = delete;
I am reasonably sure that the default constructor is only implicitly created if no other constructors are declared. So deleting the default constructor is at the least unnecessary.

Here is a trivial example:

Code:

#include <iostream>template<typename T>class Test{public:    Test(T t)    {        std::cout << t << '\n';    }};int main(){    Test<int> t;}
Which doesn't compile:

Code:

test_default.cxx: In function ‘int main()’:test_default.cxx:16:15: error: no matching function for call to ‘Test<int>::Test()’   16 |     Test<int> t;      |               ^test_default.cxx:8:5: note: candidate: ‘Test<T>::Test(T) [with T = int]’    8 |     Test(T t)      |     ^~~~test_default.cxx:8:5: note:   candidate expects 1 argument, 0 providedtest_default.cxx:4:7: note: candidate: ‘constexpr Test<int>::Test(const Test<int>&)’    4 | class Test      |       ^~~~test_default.cxx:4:7: note:   candidate expects 1 argument, 0 providedtest_default.cxx:4:7: note: candidate: ‘constexpr Test<int>::Test(Test<int>&&)’test_default.cxx:4:7: note:   candidate expects 1 argument, 0 provided

Statistics: Posted by AndyD — Thu Jan 09, 2025 9:40 pm



Viewing all articles
Browse latest Browse all 4902

Trending Articles