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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:33:14+00:00 2026-05-17T00:33:14+00:00

I have a vector class with a properly overloaded Vect*float operator and am trying

  • 0

I have a vector class with a properly overloaded Vect*float operator and am trying to create the global/non-member float*Vect operator as follows: (Note this is a heavily edited sample)

class Vect
{
    public:
        Vect::Vect(const float p_x, const float p_y, const float p_z, const float p_w);
        Vect operator*(const float p_sclr) const;
    private:
        float x;
        float y;
        float z;
        float w;
};
Vect::Vect(const float p_x, const float p_y, const float p_z, const float p_w) {
    x = p_x;
    y = p_y;
    z = p_z;
    w = p_w;
}
Vect Vect::operator*(const float p_sclr) const {
    return Vect( (x * p_sclr), (y * p_sclr), (z * p_sclr), 1); // reset w to 1
}
//Problem Non-MemberOperator
Vect operator*(const float p_sclr, const Vect& p_vect);
Vect operator*(const float p_sclr, const Vect& p_vect) {
    return p_vect * p_sclr;
}

But when I go to test the operator with the call:

Vect A(2.0f, 3.0f, 4.0f, 5.0f);
float s = 5.0f;
Vect C, D;
C = A * s; // Fine
D = s * A; // Error as below

I receive the following compile error:

error C2678: binary ‘*’ : no operator found which takes a left-hand operand of type ‘float’ (or there is no acceptable conversion)

Can anyone provide insight to why this happens? The MS documentation is available at http://msdn.microsoft.com/en-us/library/ys0bw32s(v=VS.90).aspx and isn’t very helpful Visual Studio 2008. This is the only compile error or warning I receive.

  • 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-17T00:33:15+00:00Added an answer on May 17, 2026 at 12:33 am

    The final solution was to go with a friend function because the variables were in p_vect were private:

    //class definition
    friend Vect operator*(const float scale, const Vect& p_vect);
    
    //function
    Vect operator*(const float p_sclr, const Vect& p_vect) {
       return Vect( (p_vect.x * p_sclr), (p_vect.y * p_sclr), (p_vect.z * p_sclr), 1.0f);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that has a vector member variable, which I fill up
Background: I'm trying to create my own Vector class to assist in performing mathematical
I have a vector class and I defined the __mul__ method to multiply a
I have a std::vector of some class of the form class A{ public: A():i(someNumber){}
I have a vector of pointers to class objects. These class objects invoke new
I have a vector of pointers to a class. I need to call their
I have a vector called players and a class called Player. And what I'm
I have a vector v of objects A in a Class B where each
I have a static std::vector in a class. When I use Microsoft's memory leak
I have class A: public B { ...} vector<A*> v; I want to do

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.