1

Like I said in the title, I can't pass an inner class object as argument for outer class' constructor. Below is the class header;

class Corner {
public:
    Corner(cv::Mat imageMat, int flag, feat::Corner::cornerDetectorHarris* cdh = nullptr);
    ...
    class cornerDetectorHarris {...};
    ...
};  

Visual Studio Community has no problem with the codeabove. Problem is when I try to define the function in .cpp file;

feat::Corner::Corner(cv::Mat imageMat, int flag, feat::Corner::cornerDetectorHarris* cdh) {}

VSC claims a E0493 error under the second Corner, "no instance of overloaded function "feat::Corner::Corner" matches the specified type". Here is the error code;

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0493   no instance of overloaded function "feat::Corner::Corner" matches the specified type    bpv2    C:\Users\ASUS\source\repos\bpv2\bpv2\feat.cpp   533 

If I remove the cornerDetectorHarris pointer the error goes away so I'm fairly sure it's the problem. I tried removing the default value for argument but it didn't change anything.

One Bad Student
  • 160
  • 2
  • 9
  • 2
    You need to define the `class cornerDetectorHarris` before the `Corner` constructor. – Radoslav Voydanovich Sep 04 '20 at 12:16
  • 1
    Or at least declare it before its first use. – cigien Sep 04 '20 at 12:49
  • 1
    Just as a matter of terminology, "inner class" and "outer class" have special meanings and special properties in some programming languages. In C++ a class that's defined inside another class doesn't have any special magic (other than being a member, and so, like all members, having access to private members of the class that it's defined in), and is usually referred to as a "nested class". – Pete Becker Sep 04 '20 at 13:13

1 Answers1

1

Simply declare the inner class before any methods that depend on it. You can of course even define the methods in the header if you so wish.

Not really sure why you would do it this way though; why not simply have cornerDetectorHarris declared outside and before Corner?

There is some useful discussion on the topic here: Why would one use nested classes in C++?

class Corner {

public:
    class cornerDetectorHarris {...};

    Corner(cv::Mat imageMat, int flag, feat::Corner::cornerDetectorHarris* cdh = nullptr)
    {
        //do stuff
    }
    // etc
};  
Den-Jason
  • 2,395
  • 1
  • 22
  • 17