How to initialize a string array in a default class constructor?
Pulling my hair out on this one, book doesn't show any examples and my GoogleFu is weak.
Code:
#ifndef ROMANNUMERALS_H_INCLUDED
#define ROMANNUMERALS_H_INCLUDED
#include <string>
using namespace std;
const int MAX_NUMS = 20;
class RomanNumerals
{
private:
string romanNums[MAX_NUMS];
public:
RomanNumerals()
{
string romanNums[MAX_NUMS] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX" };
}
string getRomanNumerals(int num)
{
return romanNums[num-1];
}
};
#endif // ROMANNUMERALS_H_INCLUDED
These are my warnings:
[code
C:\Users\Leonard\Desktop\New folder (2)\RomanNumerals.h||In constructor 'RomanNumerals::RomanNumerals()':|
C:\Users\Leonard\Desktop\New folder (2)\RomanNumerals.h|17|warning: unused variable 'romanNums'|
||=== Build finished: 0 errors, 1 warnings ===|
[/code]
Which is really frustrating because if I put the array directly into my main.cpp and call it like I'm trying to here, it works perfectly. Is there some magical way to setup an array in a class or constructor? Argh!