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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:21:57+00:00 2026-06-17T02:21:57+00:00

I have a question regarding references to pointers, or a pointer reference or whatever

  • 0

I have a question regarding references to pointers, or a pointer reference or whatever you want to call it, but first some code. First, an abstract compare function template class:

template <class T> struct BinaryTrivalent {
    virtual BinaryTrivalent<T>* clone() const = 0;
    virtual int operator()(const T& lhs, const T& rhs) const = 0;
    int compare(const int a, const int b) const {
        if (a < b)
            return LESS_THAN;
        else if(a == b)
            return MATCH;
        return MORE_THAN;
    }
};

And the actual use of it:

struct NodePCompare : public BinaryTrivalent<Node*> {
    NodePCompare* clone() const { return new NodePCompare(*this); }
    int operator()(const Node*& lhs, const Node*& rhs) const {
        return compare(lhs, rhs);
    }
};

The template works fine on actual types but it doesn’t seem to recognise operator as I expect it to and tells me that NodePCompare is abstract.
I’ve come across this problem in the past but I gave up trying to figure out what the problem was and just wrapped the pointer in another type.
I could do the same thing now but I would like to understand what the real issue is.
I’ve been reading up on what exactly *& is supposed to mean in this context and, unless I haven’t understood correctly, this should work fine.
This link helped a bit in understanding it: http://markgodwin.blogspot.co.il/2009/08/c-reference-to-pointer.html

Ideas anyone?

  • 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-17T02:21:58+00:00Added an answer on June 17, 2026 at 2:21 am

    Your problem is that the signature doesn’t really match.

    It should be this:

    int operator()(Node* const & lhs, Node* const & rhs) const {
        return compare(lhs, rhs);
    }
    

    The problem is where the const ends up applying. You could accomplish the same thing by saying typedef Node * base_T_arg_t; in the private section of your class and then saying this:

    int operator()(const base_T_arg_t &lhs, const base_T_arg_t &rhs) const {
        return compare(lhs, rhs);
    }
    

    Basically, the const before the * doesn’t bind to the type of the pointer as a whole, it binds to the type Node.

    The return type of clone is a red herring for two reasons. First, a function signature does not include its return type. So you are most definitely creating a definition of clone that matches the original signature and will therefore override it.

    But, if your return types didn’t match the compiler would normally give you an error. Except there’s a principle called ‘contravariance‘ that allows return types that are references or pointers to be references or pointers to a derived class when the function is overridden.

    After all, a pointer to a derived type is freely convertible to a pointer to a base type. They’re, in a sense, equivalent.

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

Sidebar

Related Questions

I have general question regarding the use of pointers vs. references in this particular
I have a question regarding applying a RTRIM on a ASP:Hyperlink statement. The code
I am going over C and have a question regarding const usage with pointers.
i have a specific problem with pointers and references, with std::vector and std::string. Some
I don't have a specific question here but I'm more looking for some guidance
Hi have some question regarding spatial and temporal locality. I have read in the
i saw some info regarding this question in several threads but non suited my
Just a quick question to clear up some confusion that I have regarding units
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have

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.