12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Quiz<br />

Up to Your Neck <strong>in</strong> <strong>C++</strong><br />

Day 5, “<strong>C++</strong> Class Frameworks and the Visual Component Model”), you will see<br />

that VCL parent objects take the responsibility for delet<strong>in</strong>g their children.<br />

Q Should I create my objects on the stack or on the heap?<br />

A That depends on the object. Large objects should be created on the heap <strong>in</strong> order<br />

to preserve stack space. Small objects and primitive data types should be created on<br />

the stack for simplicity and speed of execution.<br />

Q What’s the po<strong>in</strong>t of hav<strong>in</strong>g overloaded functions?<br />

A Overloaded functions provide you a means by which you can have several functions<br />

that perform the same basic operation and have the same function name, but take<br />

different parameters. For example, you might have an overloaded function called<br />

DrawObject(). One version might take a Circle class as a parameter, another might<br />

take a Square class as a parameter, and a third could take a class called Polygon as a<br />

parameter. By hav<strong>in</strong>g three functions with the same name, you avoid the need to<br />

have three different function names.<br />

Q Should I use a lot of <strong>in</strong>l<strong>in</strong>e functions?<br />

A That depends on the function, of course. In general, though, the answer is no.<br />

Inl<strong>in</strong>e functions should be reserved for functions that are very small or seldom<br />

used, or where execution speed is critical.<br />

1. What is a po<strong>in</strong>ter?<br />

2. What does it mean to dereference a po<strong>in</strong>ter?<br />

3. What is the return value of operator new?<br />

4. Should <strong>in</strong>stances of classes and structures be passed to functions by reference or by<br />

value?<br />

5. What does the const keyword do?<br />

6. Does the follow<strong>in</strong>g qualify as an overloaded function? Why or why not?<br />

void MyFunction(<strong>in</strong>t x);<br />

long MyFunction(<strong>in</strong>t x);<br />

7. Which is better to use, a reference or a po<strong>in</strong>ter?<br />

8. What is a class member function?<br />

9. How does the compiler treat an <strong>in</strong>l<strong>in</strong>e function as opposed to a regular function?<br />

10. What, if anyth<strong>in</strong>g, is wrong with the follow<strong>in</strong>g code snippet?<br />

char* buff = new char[200];<br />

// later...<br />

delete buff;<br />

93<br />

3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!