Re: As a programmer of both languages...
- From: James Kuyper <jameskuyper@xxxxxxxxxxx>
- Date: Wed, 12 Dec 2007 12:33:43 GMT
jacob navia wrote:
Ian Collins wrote:jacob navia wrote:Ian Collins wrote:Your ignorance continues to astound. Maybe you should take some timejacob navia wrote:You can't program in C++ without using classes. Even if you define
The difference between C and C++ is the object orientation of C++. C isAre you really dense, or just being obtuse? As you have been told many
not object oriented.
times before, C++ is a multi paradigm language. You can *choose* to
write OO or procedural code in C++.
a simple structure it is actually a class.
out and learn C++ before slagging it off.
Yes Sir!
struct A {
int age;
char *Name;
};
int main(void)
{
A jacob;
}
This is valid C++ but invalid C. In C++ each "structure" definition
is just a CLASS where all members are PUBLIC by default. I see this
explanation in all C++ books I read but in my ignorance I believe
them. Stupid isn't it?
The ability to name a type using 'A' instead of 'struct A' is just syntactic sugar, not object orientation. Note that this is also a valid C++ program:
struct A {
int age;
char *Name;
};
int main(void)
{
struct A jacob;
}
Calling structs classes isn't what makes C++ more object oriented than C. It's what you do with those structs that matters. C++'s object orientation comes primarily from the fact that it supports member functions; many other features of C++ help make object orientated code easier to write, but it's the member functions that make it an object oriented language.
When you define a struct with no member functions, whether it's called a struct or a class, you're defining something that is no more object oriented in C++ than the same code would be in C if you replace 'class' with 'struct'.
C++ does implicitly define certain special member functions even for classes with no explicitly declared or defined member functions. These include things like the default constructor, destructor, copy constructor, and copy assignment operator. However, C++'s special rules for POD (Plain Old Data) types mean that the semantics of using the special member functions for POD structs (such as A above) are identical to the semantics of the corresponding code in C. They therefore do nothing to make POD structs in C++ any more object-oriented than they are in C.
C++ does nothing magical with structs, if a struct is valid C, it is
equally valid in C++, nothing is added. Otherwise how could we use C
libraries with C++?
Both languages are still compatible at many levels. But I am not getting
crazy, the concept of CLASS is CENTRAL to the C++ language.
No, it's not. C++ classes and structs can support object orientation more completely than C structs, and that's an important part of the language, but it's built on top of C. You still have a language fully as powerful as C even if you never use the object-oriented features of C++ classes that are not supported in C. And object orientation is just one among several ways that C++ extends C. Generic programming is arguably becoming far more important in modern C++ than object orientation.
Of course you can write a hello world program without them but explainBy not using them?
me how do you ignore classes in C++?
Of course. But then you are not using C++.
If you write
int main(void) { printf("hello\n");}
you do not need classes but is it C++?
Of course it is. You can also any of the many C++ features that have nothing to do with object orientation, such as templates and exceptions. If that isn't C++, what is it?
What I am saying is obvious. But you refuse to admit the obvious..
C++ is centered around the class/inheritance concept and that is OO.
- References:
- As a programmer of both languages...
- From: Tomás Ó hÉilidhe
- Re: As a programmer of both languages...
- From: jacob navia
- Re: As a programmer of both languages...
- From: Ian Collins
- Re: As a programmer of both languages...
- From: jacob navia
- Re: As a programmer of both languages...
- From: Ian Collins
- Re: As a programmer of both languages...
- From: jacob navia
- As a programmer of both languages...
- Prev by Date: Re: C closures & lexical scoping
- Next by Date: Re: alternative to fstat ?
- Previous by thread: Re: As a programmer of both languages...
- Next by thread: Re: As a programmer of both languages...
- Index(es):
Relevant Pages
|