Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:31:12+00:00 2026-06-13T03:31:12+00:00

I have encountered c2512 error even if I declared the constructor. My code is

  • 0

I have encountered “c2512” error even if I declared the constructor. My code is like this: in my “first.h” file, I declared it like:

class myClass
{
public:
    tmpM ( cv::Mat& _model );
}

then in my “first.cpp” I did:

#include "first.h"
myClass::tmpM ( cv::Mat& _model )
{
    ...
}

Then I included this “first.h” in my “second.h”, then included this “second.h” in my “third.h”, and called this class in my “third.cpp” like this:

cv::Mat myMat ( height, width, CV_8UC3 );
tmpM aM ( myMat );

But this gives out an c2512 error, saying

no appropriate default constructor available

I indeed searched about this, and found I should build a default constructor by myself, and I tried to do it like this in my “first.h”:

class myClass
{
public:
    tmpM ( cv::Mat& _model) {};
}

Then got an error saying:

function “myClass::tmpM” already has a body

I tried several other methods to do it but still couldn’t solve it. I don’t need to build a default constructor here I think, but still bothered with it. Could someone help me?

Edit

Ok, after your suggestions, I changed it into this form:

class myClass
{
public:
myClass(cv::Mat& _model ) : tmpM (_model)
{
}
private:
cv::Mat& tmpM;
};

Then in my “first.cpp”, I got an error saying

declaration is incompatible

How could this be solved?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:31:13+00:00Added an answer on June 13, 2026 at 3:31 am

    The problem here appears to be that you’ve named your class something other than what you’ve named your constructor. They have to have the same name. Also, I’m presuming you wish the reference to the model you’re passing in to be held by the object. If you want to preserve it as a reference it must be initialized in the the constructors initializer list.

    You want:

    class myClass
    {
    public:
        myClass(cv::Mat& _model ) : tmpM (_model)
        {
        }
    private:
        cv::Mat& tmpM;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered this error Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in \VBOXSVR\ACACIASOFT\apc\spreadsheet\lib\phpexcel\PHPExcel\Autoloader.php on
I have encountered the following code: class a { public: void * operator new(size_t
I have encountered code like if (flagsDef) flagsTainted |= flagsUsed; please assist in knowing
I have encountered this declaration inside a class. I am used to program in
I have encountered this error when trying to push a subrepository to bitbucket: D:\Work\agile.crm.framework>hg
I have encountered this error: Must declare the scalar variable @UserId when i am
I have encountered a slightly unusual problem. Consider the following code: class parser {
I have encountered a problem with creating a thumbnail from an uploaded image file,
We have encountered a very strange class not found problem in our web app
I have encountered this solution for a problem I tried to solve (uncheck radio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.