Lecture 18 h.new-cpp11features.pdf - Introduction to Object-Oriented Programming COMP2011 Some New Features in C 11 Prof Andrew Horner Dr Cecia Chan Dr

Lecture 18 h.new-cpp11features.pdf - Introduction to...

This preview shows page 1 - 6 out of 16 pages.

Introduction to Object-Oriented Programming COMP2011: Some New Features in C++11 Prof. Andrew Horner Dr. Cecia Chan Dr. Cindy Li Department of Computer Science & Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China developed by Prof. Brian Mak { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.1
Image of page 1
A List of New Features in C++11 uniform and general initialization using { } -list ? type deduction of variables from initializer: auto NOT ALLOWED TO USE IN COMP2011 prevention of narrowing ? generalized and guaranteed constant expressions: constexpr Range-for -statement ? null pointer keyword: nullptr ? scoped and strongly typed enums: enum class rvalue references , enabling move semantics lambdas or lambda expressions ? support for unicode characters long long integer type delegating constructors in-cass member initializers explicit conversion operators override control keywords: override and final { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.2
Image of page 2
Part I General Initialization Using { } -Lists { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.3
Image of page 3
= and { } Initializer for Variables In the past, you always initialize variables using the assignment operator =. Example: = Initializer int x = 5; float y = 9.8; int & xref = x; int a[] = {1, 2, 3}; C++11 allows the more uniform and general curly-brace-delimited initializer list. Example: { } Initializer int x = {5}; // But = here is optional float y {9.8}; int & xref {x}; int a[] {1, 2, 3}; { horner, kccecia, lixin } @cse.ust.hk COMP2011 (Spring 2018) p.4
Image of page 4
Initializer Example 1 1 #include <iostream> /* File: initializer1.cpp */ 2 using namespace std; 3 4 int main() 5 { 6 int w = 3.4; 7 int x1 {6}; 8 int x2 = {8}; // = here is optional 9 int y { 'k' }; 10 int z {6.4}; // Error!
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 16 pages?

  • Spring '17
  • wert
  • Carriage return, Prof. Andrew Horner

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes