post  newbie Question

Bazzy (4111)   Link to this post
Neither C++ forces you to use classes...
helios (6063)   Link to this post
I don't know. I can't imagine K&R saying they specifically designed C to explicitly allow some aspects of OO, particularly when it's not that easy to do. Sure, you can have a bunch of data grouped into structures, but other than that, C doesn't provide any facilities. Encapsulation is obviously impossible because there's no way to control access to data and functions, other than telling the user "you can't touch this". Inheritance? More trouble than it's worth. Polymorphism? Sure, through generic pointers, but you better not screw up when passing types, because the type system won't help you there.

As for structures containing pointers to functions, does C allow static for structure members? Because if it doesn't, that's just stupid. You'd be duplicating the same data all over the place just for a barely more convenient notation. Instead of function(&object), object.function(&object). Even if it does allow static, it's still not really convenient.
chrisname (2541)   Link to this post
does C allow static for structure members?
I'm almost 99% certain it does. No. Just tried it:
error: expected specifier-qualifier-list before ‘static’
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘static’


I don't know. I can't imagine K&R saying they specifically designed C to explicitly allow some aspects of OO,

AAAAAAAAAAARGH I can't find it now! It was something about how C didn't go out of it's way to include OOP, but it allowed for it or something.
Last edited on

Pages: [1] [2]


This topic is archived - New replies not allowed.