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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:29:47+00:00 2026-06-07T09:29:47+00:00

this is what i mean, class V3 { public: float x,y,z; }; class V3_

  • 0

this is what i mean,

class V3
{
public:
float x,y,z;
};

class V3_
{
 public:
float x,y,z;
};

V3_ vec1;
V3 vec2 = static_cast<V3_>(vec1);

what should i do to make this cast work in compile time?

Thanks.

edit:

there seems to be some misunderstanding about what i want to do.
i can write an operator to the conversion, but i want it to be done in compile time.

here are two implementations of Vector3 that allows static_cast. i dont know how does it work, but it does work.

http://www.ogre3d.org/docs/api/html/OgreVector3_8h_source.html

http://harry-3d-engine.googlecode.com/svn/trunk/NxOgreVec3.h

i can do this cast

 void DynamicBody::SetLinearMomentum(const Vector3& vel)
 {
body->setLinearMomentum(static_cast<NxOgre::Vec3>(vel));
 }

i would like an explanation on how i can do this.

edit:

upon further investigation i found how it actually does this,
it calls

template<class user_xyz_vector_type>
inline user_xyz_vector_type as() const { ... }

that is not an actual static_cast, but compiler accepts it as one.
i really hoped casting pods to eachother was an actual thing.

  • 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-07T09:29:48+00:00Added an answer on June 7, 2026 at 9:29 am

    This cast will not work at any time. You can’t static_cast completely unrelated and not convertible types to each other.

    I’m not sure what you are trying to do, so I don’t know what the work “work” means in this case, but at a raw memory level the conversion can be performed by reinterpret_cast

    V3 vec2 = reinterpret_cast<V3_&>(vec1);
    

    but this is an ugly hack that is not guaranteed to work, since, again, your types are unrelated. With the same degree (or even better) of success you can simply memcpy one object into another.

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

Sidebar

Related Questions

What does a syntax like this mean in C#? public abstract class HostFactory<TApp> :
What does it mean when a class is declared like this: class CP_EXPORT CP_Window
std::string x(x); This crashes very badly on my compiler. Does this mean I should
I have this code:( BITMAPS is a free name) class BITMAPS{ public: static ALLEGRO_BITMAP
I new to C#, Sometime I see C# code like this public class ClassName
If a class is a local inner class, does this mean that it is
Does this mean I can't update another table from a trigger if I'm using
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql
What does this mean and why am I getting this error. Any suggestions on
What does this mean? * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*

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.