I am new at C++ and this is my first post here. I am trying to understand initializer lists. The problem is that I get more and more confused. I have made a simple program, that is of no use, but I get a warning I don't understand.
#include <iostream>
using namespace std;
class Base{
private:
string monkey2 = "";
string monkey1 = "";
public:
Base(string) : monkey2{monkey1}{
cout << "monkey1 " << monkey1 << endl;
cout << "monkey2 " << monkey2 << endl;
}
};
int main()
{
return 0;
}
The warning I get is:
field 'monkey' is uninitialized when used here
and an arrow pointing on the row directly below public:.
The strange thing is if I change the order of the strings from:
private:
string monkey2 = "";
string monkey1 = "";
public:
To:
private:
string monkey1 = "";
string monkey2 = "";
public:
The warning disappears and I don't understand why. I can compile it using g++ but when using my editor vim with YCM and Clang 7.0.0 i get a warning. I have tried to activate as much warnings as i can in g++, but I can not get the same warning. Is my code or. or is it Clang?