Why we need to put const in front of array of string , dealing with enumeration. I want to convert from number enum to string | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Why we need to put const in front of array of string , dealing with enumeration. I want to convert from number enum to string

Why we need to put const in front of array of string , dealing with enumeration. I want to convert from number enum to string . I mean this const string str[8] #pragma once #include <iostream> using namespace std; #include<string> enum KOLONA { A, B, C, D, E, F, G, H }; const string str[8] = { "A","B","C" ,"D", "E", "F", "G", "H" }; class Polje { KOLONA kol; int red ; public: Polje(); Polje(KOLONA koll,int redd) :kol(koll),red(redd) { } friend bool operator==(const Polje& p1, const Polje& p2) { return (p1.kol == p2.kol) & (p1.red == p2.red); } friend bool operator+ (const Polje& p1, const Polje &p2) { return (p1.kol == p2.kol) || (p1.red == p2.red); } friend bool operator/(const Polje& p1, const Polje& p2) { return (p1.kol-p2.kol)==(p1.red-p2.red) ; } const string getKol() { return str[kol]; } int getRed() { return red; } ~Polje(); };

29th Dec 2018, 11:38 AM
Nikola
Nikola - avatar
1 ответ
+ 1
So you're saying it will fail the getKol() function if your string array wasn't constant? If so, what does the error say?
29th Dec 2018, 4:49 PM
Zeke Williams
Zeke Williams - avatar