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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:55:52+00:00 2026-06-17T06:55:52+00:00

I have a template with this static cast operator: operator Vector2<float>() const { return

  • 0

I have a template with this static cast operator:

operator Vector2<float>() const
{
    return Vector2<float>(x, y);
}

This implies to me that if I cast as a float, it will return a float variant of the class, even if x and y are integers from an integer variant. But apparently not so:

As a test:

Vector2<float>position=static_cast<float>(Vector2<int>(5,5));

I get the compiler error for *No matching conversion for static_cast from Vector2 to float*.

Yet, the conversion is specified above, is it not, as a static cast overload?

  • 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-17T06:55:53+00:00Added an answer on June 17, 2026 at 6:55 am

    You should use it like this:

    Vector2<float> position = static_cast<Vector2<float>>(Vector2<int>(5,5));
    

    since the declaration specified a conversion to Vector2<float>, not a conversion to float.

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

Sidebar

Related Questions

template <typename E> class VecExpression{ public: operator E&(){ return static_cast<E&>(*this); } operator E const&()
I have code that looks like this: template<class T> class list { public: class
I have this template: template <class T> v8::Handle<v8::Value> jsFunctionTemplate(const v8::Arguments &args) { T *t
I have template that looks like this: 100 template<size_t A0, size_t A1, size_t A2,
So I have this template design that is currently absolutely positioned, but I'm trying
Absolute beginner question: I have a template file index.html that looks like this: ...
I defined two classes: class Token_ { public: virtual char operator*()const = 0;//this fnc
I have this setup: class DontUse; template<class T,class U = DontUse, class V =
I have a class that uses an add-on template to add additional functionality as
I have template < typename threadFuncParamT > class ThreadWrapper { public: static int ThreadRoutineFunction(void*

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.