HW 10

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

T/F Multiple assignment statements (e.g. a = b = c) work because the build-in assignment operator is implemented so that it returns the value of its left operand after the assignment has been performed.

True

T/F A class copy constructor is called when: A varaible/object is being initialized from an object of the same class.

True

What will be output when the following C++ program runs? #include <iostream> using namespace std; class Dilbert{ private: int a; int b; int c; public: Dilbert( int i=0, int j=0, int k=0 ); void setABC( int i, int j, int k ); void mystery() const; int getA() { return a; } int getB() { return b; } int getC() { return c; } }; //end class dilbert int main(int argc, const char * argv[]){ Dilbert d1; cout << d1.getA() << " "; cout << d1.getB() << " "; cout << d1.getC() << "\n"; return 0;} Dilbert::Dilbert( int i, int j, int k){ this->a = i; this->b = j; this->c = k;} void Dilbert::setABC(int m, int n, int o){ a = m; b = n; c = o;} void Dilbert::mystery() const{ cout << this << endl;}

0 0 0

The ____________ operator may be used to assign one object to another, or to initialize one object with another object's data. By default, each member of one object is copied to its counterpart in the other object.

=

T/F A class copy constructor is called when: An object is going out of scope.

False

T/F A class copy constructor is called when: An object is instantiated by invoking a convert constructor.

False

T/F A class copy constructor is called when: The class contains overloaded operators that are no members of the class.

False

T/F A class copy constructor is called when: A function is called with a value parameter of the class.

True

T/F A class copy constructor is called when: A function is returning a value that is an object of the class.

True

#include <iostream> using namespace std; class Dilbert{ private: int a; int b; int c; public: Dilbert( int i=0, int j=0, int k=0 ); void setABC( int i, int j, int k ); void mystery() const; int getA() { return a; } int getB() { return b; } int getC() { return c; } }; //end class dilbert int main(int argc, const char * argv[]){ Dilbert d1; d1.mystery(); return 0;} Dilbert::Dilbert( int i, int j, int k){ this->a = i; this->b = j; this->c = k;} void Dilbert::setABC(int m, int n, int o){ a = m; b = n; c = o;} void Dilbert::mystery() const{ cout << this << endl;}

a hexadecimal memory address

What action is performed by a class' default copy constructor?

a memberwise assignment

The class Stuff has both a copy constructor and an overloaded =operator. Assume that blob and clump are both instances of the Stuff class. For the statement below, indicate whether the copy constructor or the overloaded = operator will be called: Stuff splat = clump;

copy constructor

The class Stuff has both a copy constructor and an overloaded =operator. Assume that blob and clump are both instances of the Stuff class. For the statement below, indicate whether the copy constructor or the overloaded = operator will be called: showValues(blob); //blob is passed by value

copy constructor

T/F All C++ operators may be overloaded

false

T/F A copy constructor is a special constructor that is called whenever a new object is created and initialized with the data of another object of a different class.

false (same class)

A(n) ___________________ is a function that is not a member of a class, but has access to the private members of the class.

friend

The class Stuff has both a copy constructor and an overloaded =operator. Assume that blob and clump are both instances of the Stuff class. For the statement below, indicate whether the copy constructor or the overloaded = operator will be called: clump = blob;

overloaded = operator

Every instance of a class maintains a hidden pointer to itself. The identifier of that pointer is:

this

T/F A copy constructor must have a single parameter that is a reference to the same class. Forgetting the & that identifies reference parameters will result in compiler errors.

true

T/F If the programmer does not specify a copy constructor for the class, then the compiler automatically calls a default copy constructor when necessary.

true

T/F In addition to providing a means for the creation of objects, convert constructors provide a way for the compiler to convert a value of a given type to an object of the class.

true


संबंधित स्टडी सेट्स

Business Continuity And Disaster Recovery

View Set

Psych 3420 Prelim 1, Psych 3420 prelim 2, Psych 3420 Final

View Set

TEXT: McCulloch v. Maryland, Part II

View Set

LaCharity Chapter 7: Cardiovascular Problems

View Set

3MA114 - Management pro informatiky a statistiky

View Set

Nutrition 330 Study Questions 1-7

View Set

Unit 5: Lesson 5.1, Lesson 5.2, Lesson 5.3

View Set