Solved

c ++ True and False Questions

Posted on 2011-03-17
5
269 Views
Last Modified: 2012-06-21
I need to figure if these are true or false, any help would be greatly appreciated...

8.  If B is a base class of D, then D’s members cannot access the private data members of B without regard to the kind of inheritance.

9.  An overloaded operator= function must be a non-static class member.

10. One constructor of a class can call another constructor of the same class to initialize the this object

11. When overloading (), [], -> or any assignment operator, the operator overloading function must be declared as a class member.

12. A copy constructor is used to initialize an object with another object of the same class. Copy constructors are also invoked whenever a copy of an object is needed, such as in call-by-value, and when returning a value from a called function. In a copy constructor, the object being copied must be passed in by reference.

13. To overload the increment operator to allow both pre-increment and post-increment usage, each overloaded operator function must have a distinct signature so the compiler will be able to determine which version of ++ is intended.

14. Derived classes can provide their own implementations of a base class virtual function if necessary, but if they do not, the base class's implementation is used.

15. With single inheritance, a class is derived from only one base class. With multiple inheritance, a derived class inherits from multiple (possibly unrelated) base classes.

16. A derived class cannot access the private members of its base class; allowing this would violate the encapsulation of the base class. A derived class can, however, access the public and protected members of its base class.

17. An object of a derived class can be treated as an object of its corresponding public base class. However, the reverse is not true.

18. When deriving a class from a private base class, public and protected members of the base class become private members of the derived class.

19. For a derived-class object, first the base-class constructor is called, then the derived-class constructor is called (which may call member object constructors).

20. An attempt by a const member function of a class to modify an object of that class is a syntax error.
0
Comment
Question by:villmund
5 Comments
 
LVL 32

Expert Comment

by:phoffric
Comment Utility
Tell us what you think the answer is and the reason for it.

Here is some light reading material:
    http://www.experts-exchange.com/help.jsp?hi=21

    http://www.experts-exchange.com/help.jsp?hi=23
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
It's probably more useful if you give us the answers you think are correct (and your reasoning), and then we can confirm or correct them.
0
 

Author Comment

by:villmund
Comment Utility
This is what I have for the answers
8.  T
9.  T
10. F
11.  T
12. T
13. F
14. T
15.  T
16.  T
17. F
18. F
19. T
20. T
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
Comment Utility
>> 8.  T
>> 9.  T
>> 10. F
>> 11.  T
>> 12. T

All correct.

>> 13. F

The signature of an overloaded pre-increment operator is different from that of an overloade post-increment operator. The latter must have a dummy int parameter, while the former doesn't.

>> 14. T
>> 15.  T

Correct.

>> 16.  T

Assuming public inheritance, yes.

>> 17. F

This one has a slightly simplified view on things, but  the statement is correct when looked at in the right view. Public inheritance models an "is a kind of" relationship between the derived and base class. Eg. a student is a kind of person, but a person is not necessarily a student.

>> 18. F

This statement describes what private inheritance means.

>> 19. T

The statement is reasonably accurate indeed.

>> 20. T

Not necessarily. There is for example such a thing as mutable data members.
0
 
LVL 12

Expert Comment

by:trinitrotoluene
Comment Utility
>>16. A derived class cannot access the private members of its base class; allowing this would violate the encapsulation of the base class.

you could still have a public function in your base class which provides access to the private members. The question can be interpreted in this way as well. So the better way to put it is that a derived class cannot directly access the private members of its base class.

>>20. An attempt by a const member function of a class to modify an object of that class is a syntax error.
such an attempt will be prevented by the compiler. So it is semantically incorrect and doesn't really fall under the category of a pure syntax error. Like infinity said a "mutable" member can be modified within a const member function.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sum28 challenge 31 95
only14 challenge 19 63
Unresolved External Symbols 3 53
Change to event 1 72
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now