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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:31:02+00:00 2026-05-21T10:31:02+00:00

I have this working on G++ but on Visual Studo 2008 this will not

  • 0

I have this working on G++ but on Visual Studo 2008 this will not compile.

template<typename T, typename DerivedT >
struct Foo
{    
    template<typename Scale>
    DerivedT operator * (const Scale i)
    {
     DerivedT result;
     return result;
    }
};

template<typename T>
struct Bar : public Foo<T, Bar<T> >
{   
    // Removing this operator gets rid of the error.
    Bar& operator * (const Bar& boo)
    {
     return *this;
    }
};

int main()
{
    Bar<float> bar;
    bar = bar * 3;

    return 0;
}

I get the error

Error   1   error C2679: binary '*' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)

Even if I define the Foo operator as an int/double/float explicitly it returns the same error message. Is there any way of getting past this?

EDIT:
This only falls apart when the derived class overload the operator * that is also defined in the Base class.

  • 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-21T10:31:03+00:00Added an answer on May 21, 2026 at 10:31 am

    I don’t know how you managed to compile this by g++ (and I actually doubt that), but your code is indeed not compilable for rather obvious reasons. Your Bar class exposes only one operator *

    Bar& operator * (const Bar& boo)
    

    and that operator expects a Bar object as a right-hand size operand. 3 will not work, 3 is not Bar and is not convertible to Bar.

    The base class’s operator * is the one that might have worked here, but it is hidden by the derived class’s operator. This is why, as one would expect, removing the derived class’s operator * gets rid of the error.

    You can simply add the

    using Foo<T, Bar<T> >::operator *;
    

    to the definition of Bar to unhide the base class’s operator and it should compile.

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

Sidebar

Related Questions

This was working correctly in Visual Studio 2008, but since I have switch to
I have this query working but it is not returning back exactly what I
Ok, so basically I have this part of the .htaccess partly working, but not
I currently have this working but it requires me to have a static method
I think I have this working but I need advice. I'd like to know
I have this regex working but now need to allow numbers without the decimal
I have this working great, but I'd like a deeper understanding of what is
I have this working code, but now i need to be able to change
this seems to be weird but it really happened. I have this code working
Sorry if this is obvious but have looked around and can't get this working:

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.