{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs31 lecture 17

A data region is allocated to store it bar 42

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e] [attributes }; x Implementation of a method: <type> <classname>::<methodname>([arguments])
 { … } 115 More on the syntax x Declaring an instance of a class in a program <type> <objectname>; x Getting/setting the value of a public attribute of a class from outside Getting/setting its implementation its <objectname>.<attributename> x Getting/setting the value of am attribute of a class from inside its Getting/setting implementation implementation <attributename> x Calling a public method of a class (from outside)
: <objectname>.<methodname>([arguments])
 x Calling a public method of a class (from inside)
: 116 A first example struct Car { int uniqueId; int void displayId()
; void }; }; void Car::displayId()
 { void std::cout << uniqueId << std::endl; std::cout } int main()
 { Car c; Car c.uniqueId = 123; c.uniqueId c.displayId()
; c.displayId()
; } 117 Classes and namespaces x They are not to be confused!! x A namespace is just a prefix around the names of types / variables x A class is a type, and objects/variables of this type can be declared x Namespaces and classes can be combined: namespace foo { int global1; int struct bar { struct int attrib1; int }; }; } foo::bar object1; foo::bar object2; object1.attrib1 = 42; object2.attrib1 = 43; foo::global1 = 1; 118 The lifetime of an object x Example for a variable: void foo()
 { int bar; // The variable is declared. A data region is...
View Full Document

{[ snackBarMessage ]}

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