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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:50:44+00:00 2026-05-22T11:50:44+00:00

Greetings all. I am writing some code using the Boost Units library and have

  • 0

Greetings all.

I am writing some code using the Boost Units library and have run into a problem.

I have managed to abstract the problem from Boost code so you won’t be looking through reams of boost template meta programming. Though I’m sure if you have experience with that it could help. Here is the reproduction:

class Base{};
class Derived : public Base
{
public:
  Derived(){}
  Derived(const Base &){}
};

class Q {};
class U
{
public:
  template< typename Y >
  Q operator * (Y)
  {
    Q r;
    return r;
  }
};

Base operator * (U, const Base &)
{
  Base r;
  return r;
}

int main(int argc, char **argv)
{
  Base myBase;
  U myU;
  Base myOtherBase = myU * myBase;
  Derived myDerived;
  Derived myOtherDerived =  myU * myDerived;
  return 0;
}

So the problem (specifically) is as follows: myU * myBase uses operator * (U, const Base &) and returns type of Base, all good so far. Whereas myU * myDerived insists on using generalised U::operator * (Y) and hence returns a Q, no good because I wanted a Base again.

Now, all classes other than Base and Derived are boost library classes so I cannot modify the members of U. How do I “beat” U::operator * (Y) for overload/template deduction/instantiation, in this case, in an elegant and “solved once and for ever” manner.

I am using MSVC++ 2008 in case it is relevant to anyone.

Edit: Added a possible (quite likely) solution in answers

  • 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-22T11:50:45+00:00Added an answer on May 22, 2026 at 11:50 am

    Just as I gave up trying to solve this last night the answer hit me like a brick. The Q typed result of U::operator*(Base) is conceptually the same as the Base typed result of operator*(U,Base), even though they are being represented by different Types. All I need to do is provide a constructor for Base ( const Q & ) that accepts type Q.

    class Base
    {
    public:
    Base(){}
    Base(const Q &){}
    };
    

    This makes my example compile. Now to see if I can actually write the desired constructor in the real version (where a Base is actually a Base<Q,...> and the Q we accept is a Q<Base,...>).

    Unfortunately, presenting a simplified abstract example of the problem made it harder to spot this solution, so I had quite an advantage. Thanks go out to all who chipped in with ideas / comments and answers.

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

Sidebar

Related Questions

Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files
Greetings to all! This is my first question here on stackoverflow. I have a
I am new here so first of all my greetings to you I am
Greetings! I'm working on wrapping my head around LINQ. If I had some XML
Greetings, I'm trying to find either a free .NET library or a command-line executable
Greetings, The VBA code below will create an Excel QueryTable object and display it
Greetings, I'm trying to find a way to 'unbind' a socket from a particular
Greetings. I'm looking for a way to parse a number of XML files in
Greetings, I need a way (either via C# or in a .bat file) to
Greetings! I am trying to check directory write-permissions from within a Windows MFC/ATL program

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.