Initializing Variables with Uniform initialization in C++11 - C++ Language Basics

C++ examples for Language Basics:Variable

Description

Initializing Variables with Uniform initialization in C++11

Demo Code

#include <iostream>

using namespace std;

class MyClass/*from w ww . ja v a2s. c  o m*/
{
private:
  int intValue;

public:
  MyClass() = default;
  MyClass(const MyClass& rhs) = default;
};

int main()
{
  MyClass objectA;
  MyClass objectB{ MyClass{} };

  int number{ 0 };
  char another{ 68 };

  double bigNumber{ 1.0 };
  float littleNumber{ 1.0 };

  cout << number << endl;

  cout << bigNumber << endl;

  return 0;
}

Result


Related Tutorials