Answers for "what is initialization list in c++"

C++
1

c++ class member initialization

class Test  {
private:
  std::string data;
public:
  test(std::string data) : data(data) {}
  std::string getData() {
    return data;
  }
};

int main() {
  Test test("This is just some random Text");
  std::cout << test.getData() << std::endl;
  return 0;
}
Posted by: Guest on June-10-2020
-2

c++ initialization list

class Something
{
private:
    int m_value1;
    double m_value2;
    char m_value3;
 
public:
    Something()
    {
        // These are all assignments, not initializations
        m_value1 = 1;
        m_value2 = 2.2;
        m_value3 = 'c';
    }
};
Posted by: Guest on April-19-2020

Browse Popular Code Answers by Language