Unnecessary C++ features?

Started by
70 comments, last by null_pointer 23 years, 9 months ago
quote:
Original post by foofightr

Maybe you haven't heard, but C doesn't have constructors.


C doesn't allow to create variables anywhere either, but since this is a C++ thread it doesn't matter

The example was in response to your statement:

quote:
The only use I can see of this C++ feature (declaring vars virtually anywhere) is that it helps code readability


Which is true for basic types, but most C++ programs have user defined types with sometimes complicated constructors.

quote:
However, you do have a point about the "slow resources" stuff. I wouldn't do things this way however.


I almost always use a construct to allocate resources (memory, files, etc) and free them in the destructor. It keeps my code exception safe and avoids any messy 'tidy up' code at the end of a function.

Edited by - Wilka on July 17, 2000 6:20:09 PM
Advertisement
Anonymous Poster:

I said that the compiler should remove a function from the final binary if it was never referenced (meaning called or its address taken).

Try this in a C++ compiler:


/////////////
// in one.cpp:
void myfunction1()
{
}

/////////////
// in two.cpp:
void myfunction2()
{
myfunction1(); // error
}

void main()
{
}



Since in C++ you must prototype all of your functions before using them in other modules, it is as if all functions are static until prototyped, no? Or perhaps I am misunderstanding the use of the C ''static'' keyword?



- null_pointer
Sabre Multimedia

This topic is closed to new replies.

Advertisement