ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

Answer1


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

Archive

WHAT'S YOUR ENGINEERING QUOTIENT?

Test Your EQ•Step up to the Plate.

Problem 1Itýs not uncommon for C programmers to write code that resembles object-oriented programming techniques. The following structure is a good example of a C implementation of an object. Why would a C++ class be more efficient in terms of data space than this C construct?

struct c_obj {
int x, y; 
void (*create)();
void (*show)();
void (*hide)();
void (*delete)(); };



Answer: The C++ equivalent, shown here, is more efficient than the typical C equivalent because the C++ class does not actually store a pointer for each virtual function. Instead, it stores a pointer to an array of functions (virtual function table) so each instance of cpp_obj is smaller than each struct c_obj.

class cpp_obj {
public:
int x, y;
void create(void);
void show(void);
void hide(void);
void delete(void);
};

4-00


For questions or comments about
Test Your EQ, e-mail eq@circuitcellar.com
.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ