Why does __null, 0, 0.0 work but (void *)0,nullptr dont work when assignment overload is used

why does __null, 0, 0.0 work but (void *)0,nullptr dont work when assignment overload is used
Take for example


#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/types_c.h>
#include<iostream>
using namespace cv;

int main(int argc, char** argv) {
   Mat frame;
   frame = (void *)0;  
   Mat frame2;
   frame2 = nullptr;
   return 0;
   }

the above throws overload errors

/home/shft/build/test/hello.cpp:9:10: error: no viable overloaded '='
   frame = (void *)0;
   ~~~~~ ^ ~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1073:10: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'const cv::Mat' for 1st argument
    Mat& operator = (const Mat& m);
         ^
/usr/local/include/opencv4/opencv2/core/mat.inl.hpp:3008:11: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'const cv::MatExpr' for 1st argument
Mat& Mat::operator = (const MatExpr& e)
          ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1260:10: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'const cv::Scalar' (aka 'const Scalar_<double>') for 1st argument
    Mat& operator = (const Scalar& s);
         ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2101:10: note: candidate function not viable: cannot convert argument of incomplete type 'void *' to 'cv::Mat' for 1st argument
    Mat& operator = (Mat&& m);
         ^
/home/shft/build/test/hello.cpp:11:11: error: no viable overloaded '='
   frame2 = nullptr;
   ~~~~~~ ^ ~~~~~~~
/usr/local/include/opencv4/opencv2/core/mat.hpp:1073:10: note: candidate function not viable: no known conversion from 'std::nullptr_t' to 'const cv::Mat' for 1st argument
    Mat& operator = (const Mat& m);
         ^
/usr/local/include/opencv4/opencv2/core/mat.inl.hpp:3008:11: note: candidate function not viable: no known conversion from 'std::nullptr_t' to 'const cv::MatExpr' for 1st argument
Mat& Mat::operator = (const MatExpr& e)
          ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1260:10: note: candidate function not viable: no known conversion from 'std::nullptr_t' to 'const cv::Scalar' (aka 'const Scalar_<double>') for 1st argument
    Mat& operator = (const Scalar& s);
         ^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2101:10: note: candidate function not viable: no known conversion from 'std::nullptr_t' to 'cv::Mat' for 1st argument
    Mat& operator = (Mat&& m);

But __null or any integer literal work (on my system NULL is defined as nullptr as a macro definition

if you just want an empty Mat, say cv::Mat the_mat; and that’s it. it’s an empty Mat with no size.

if you want a Mat of a certain size, initialized to all zero values, use cv::Mat the_mat = cv::Mat::zeros(...) with appropriate arguments.


you shouldn’t do any “assigning pointers”. Mats aren’t pointers. don’t assign pointers, or anything zero/null-like.

Mats are actual objects.

C++ has the concept of “RAII”, which basically means you don’t use pointers for objects (heap allocation) but you instantiate them on the stack, so they’re cleaned when the function ends.

Mat objects additionally have logic for reference counting, like std::shared_ptr.

They also have some “broadcasting” rules. if you assign a number, it’s broadcast to all the matrix elements. that works for anything that’s a number, but not for pointers, because pointers are pointers, not numbers.

please review a few C++ basics and perhaps some of the example code found in the OpenCV docs.