简体   繁体   中英

int' to float' requires a narrowing conversion

I'm getting the conversion compiler error while converting from type_1 to type_2

CoordF character_coord() const { return character_coord_; };
void Set_character_coord(int x, int y) { character_coord_ = { x, y }; }; //line with error
void Set_character_coord(CoordF char_coord){ character_coord_ = char_coord; };

float vert_speed() const { return vert_speed_; };
void Set_vert_speed(float vert_speed) { vert_speed_ = vert_speed; };

camera_.Set_camera_coord({ screen_width_ / 2, screen_height_ / 2 }); //another example of same error 
camera_.Set_camera_size( screen_width_, screen_height_);

any help will be much appreciated

{} operator implies that you do not want cast. Use () maybe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM