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

  • Home
  • SEARCH
  • 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 1078061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:40:10+00:00 2026-05-16T21:40:10+00:00

I want to mock a method with the declaration A::B X(void) . The definition

  • 0

I want to mock a method with the declaration A::B X(void). The definition is something as follows.

class A {
    class B;
    virtual B X() = 0;
};

class A::B {
  public:
    auto_ptr<int> something;
};

My mock class, following this, is quite standard.

class mA : public A
{
  public:
    MOCK_METHOD0(X, A::B());
};

Compiled, however, this gives me this weirdo error, and I haven’t been able to track it down. What is wrong with this?

In member function ‘virtual A::B mA::X()’:
...: error: no matching function for call to ‘A::B::B(A::B)’
...: note: candidates are: A::B::B()
...:                       A::B::B(A::B&)

Update I have found a failing code sample to demonstrate this.

#include <gmock/gmock.h>
#include <memory>
using std::auto_ptr;

class thing {
  public:
    class result;
    virtual result accessor () = 0;
};

class thing::result {
    auto_ptr<int> x;   // If this just "int", error goes away.
};

namespace mock {
    class thing : ::thing {
      public:
        MOCK_METHOD0 ( accessor, result() );
    };
}
  • 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-16T21:40:10+00:00Added an answer on May 16, 2026 at 9:40 pm

    It is hard to tell without the definitions of A and B. sounds like it is trying to construct a B from a temporary and failing because it can’t bind the temporary to a non-const reference.

    For example, your copy constructor might be defined as:

    class A {
     public:
      class B {
       public:
        // This should be const, without good reason to make it otherwise.
        B(B&); 
      };
    };
    

    With the fix just making it a const reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to mock only the GetValue method of the following class, using Moq:
I want to mock a particular method of a class, problem i am facing
I have a class which has a internal method and i want to mock
Is it possible to do something like that with EasyMock: class ClassName{ void method(){
I want to mock a method of a class and execute a callback which
I want to mock a method in the same class that I am testing.
I want to mock Find method which expects a predicate using Moq: public PurchaseOrder
I have the following class: public abstract class AbstractParent { static String method() {
I want to mock an inherited protected method. I can't call this method directly
I want to mock a method that returns a complex datatyp class aClass {

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.