jeudi 16 décembre 2021

How to make the conversion from 'int' to 'char' reasonable under -Werror=conversion option? c++11

error: conversion from ‘int’ to ‘char’ may change value [-Werror=conversion]

build cmd example: g++ -std=c++11 test.cpp -o a.out -Werror=conversion

    auto index = 3;
    char singleChar = 'A' + index; // I want to get A-Z

I hope sigleChar is dynamically assigned. could you pls help me to solve this error report without using switch? How would it be better to write code?

Aucun commentaire:

Enregistrer un commentaire