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 6097351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:02:00+00:00 2026-05-23T13:02:00+00:00

Using Visual Studio 2010 C++ with googlemock. I’m trying to use a mock I

  • 0

Using Visual Studio 2010 C++ with googlemock. I’m trying to use a mock I created and I’m getting the compiler error on the line:

EmployeeFake employeeStub;

The error is:

1>c:\someclasstests.cpp(22): error C2512: 'MyNamespace::EmployeeFake' : no appropriate
default constructor available

EmployeeFake:

class EmployeeFake: public Employee{
 public:
  MOCK_CONST_METHOD0(GetSalary,
      double());
}

Employee:

class Employee 
{
public:
    Employee(PensionPlan *pensionPlan, const char * fullName);
    virtual ~Employee(void);

    virtual double GetSalary() const;
}

I gather that the problem is that the base class doesn’t have a default constructor but how should I fix this? Do I need to add a default constructor to my base class? Or do I need to add a constructor to my mock class? Or something else?

  • 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-05-23T13:02:00+00:00Added an answer on May 23, 2026 at 1:02 pm

    You can just add a constructor to your mock that delegates to the Employee constructor:

     class MockEmployee : public Employee {
         public:
             MockEmployee(PensionPlan* pension_plan, const char* full_name)
             : Employee(pension_plan, full_name) {}
             // ...
     };
    

    Then construct MockEmployee like you would construct Employee. However, there are a couple things that can be improved about this code that I would highly recommend and that would simplify this:

    1. Make Employee pure virtual (with a protected default constructor).
    2. Rename the current Employee implementation to a name that describes the kind of employee (e.g. FullTimeEmployee or EmployeeWithPensionPlan) and make it inherit from the pure virtual type.
    3. Use “virtual ~Employee()” instead of “virtual ~Employee(void)” (using void explicitly in the parameter is a hold over from C and is out of vogue in most C++ communities as far as I’m aware).
    4. Use “const string&” instead of “const char*” for the name.

    So, to clarify, my recommendation would be:

    class Employee {
        public:
            virtual ~Employee() {}
            virtual double GetSalary() const = 0;
        protected:
            Employee() {}
    };
    
    class FullTimeEmployee : public Employee {
         // your concrete implementation goes here
    };
    
    class MockEmployee : public Employee {
        public:
            MockEmployee() {}
            virtual ~MockEmployee() {}
            // ... your mock method goes here ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Visual Studio 2010 and created database tables with relationships. Is there an
Using Visual Studio 2010, is there a way to run all unit tests in
Using Visual Studio 2010 .Net Framework 4 C# Linq to Entities Issue I would
Using Visual Studio 2010 How can I enumerate all resources within in a specific
I am using Visual Studio 2010 ultimate and have a solution that contains a
I’m using Visual Studio 2010 to write unmanaged C++ code. When debugging, anything printed
I'm using Visual Studio 2010 Ultimate, and it seems that I cannot suppress warnings
I'm using Visual Studio 2010. I work with mostly windows services and web services.
I'm currently using Visual Studio 2010 (and also have a copy of Visual Studio
I'm using Visual Studio 2010. I have a class with the following constructor: CVideoAnnotation::CVideoAnnotation(std::string

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.