0
votes

While writing code I observed that if i declare unmanaged classs before managed class the code compiles with no error:

#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>

using namespace System;

namespace OpenCVDll
{
    public class OpenCV
    {
    public:
        //members
        cv::Mat CalibrationDark;
        cv::Mat CalibrationBright;
        unsigned short* dark;
        unsigned short* bright;

        //methods
        void DarkCalibration();
        void BrightCalibration();
        OpenCV(){}
        ~OpenCV();
    };

    public ref class MOpenCV
    {
    public:
        //members
        OpenCV* UOpenCV; 

        //methods
        MOpenCV();
        !MOpenCV();
        ~MOpenCV();

    private:
        //methods
        void Destruction();
    };
}`

However if I declare the classes other way around, first managed and then unmanaged:

#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\highgui\highgui.hpp>

using namespace System;

namespace OpenCVDll
{
    public ref class MOpenCV
    {
    public:
        //members
        OpenCV* UOpenCV; 

        //methods
        MOpenCV();
        !MOpenCV();
        ~MOpenCV();

    private:
        //methods
        void Destruction();
    };

    public class OpenCV
    {
    public:
        //members
        cv::Mat CalibrationDark;
        cv::Mat CalibrationBright;
        unsigned short* dark;
        unsigned short* bright;

        //methods
        void DarkCalibration();
        void BrightCalibration();
        OpenCV(){}
        ~OpenCV();
    };
}

I get missing type error: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Why is it so?

1

1 Answers

1
votes

The problem is that when the compiler gets to the line OpenCV* UOpenCV;, the class OpenCV has not been declared yet.

You can solve this with a forward declaration of the OpenCV class before the MOpenCV class.

public class OpenCV;

public ref class MOpenCV
{
public:
    //members
    OpenCV* UOpenCV; 

    ...
};

public class OpenCV
{
    ...
};