Personal computing discussed
Moderators: renee, SecretSquirrel, just brew it!
CampinCarl wrote:Well, mostly with trying to deal with class design/structure, class inheritance hierarchies, etc.. For instance, it doesn't seem like there is any existing language support for a generic interface class. How is that accomplished in CPP? Some sort of strange virtual class or something? Or not at all?
class SomeInterface
{
virtual ~SomeInterface() {}
// methods
virtual void Foo(int someIndex) = 0;
virtual in Bar() = 0;
// you have to roll your own setter/getter
virtual void Enabled(const bool& flag) = 0;
virtual bool Enabled() = 0; // forgot offhand if you can declare this function const :P
};
class RealClass : public SomeOtherClass, public SomeInterface, public SomeOtherInterface
{
public:
RealClass() : _enabled(false) {}
virtual ~RealClass() {} // pretty much should declare your destructors virtual more often than not
// SomeInterface implementation
virtual void Foo(int someIndex) { /* ... */ }
virtual in Bar() { /* ... */ }
virtual void Enabled(const bool& flag) { _enabled = flag; }
virtual bool Enabled() { return _enabled; }
// implement other overrides and the virtual=0 functions
private:
bool _enabled; // store the property
};
just brew it! wrote:The biggest differences are that C++... is essentially a superset of C (and inherits all of C's low-level features like pointers, explicit memory management, etc.)
Buub wrote:just brew it! wrote:The biggest differences are that C++... is essentially a superset of C (and inherits all of C's low-level features like pointers, explicit memory management, etc.)
I strongly disagree. It may have started that way, but modern C++ is a very rich language all its own, and only works best when you move away from C paradigms. Logically, I feel it's far more useful to consider C++ a deep object-oriented language with very good C compatibility.
just brew it! wrote:Buub wrote:just brew it! wrote:The biggest differences are that C++... is essentially a superset of C (and inherits all of C's low-level features like pointers, explicit memory management, etc.)
I strongly disagree. It may have started that way, but modern C++ is a very rich language all its own, and only works best when you move away from C paradigms. Logically, I feel it's far more useful to consider C++ a deep object-oriented language with very good C compatibility.
Yes, I agree that is how it is *intended* to be used. But in the real world, you see an awful lot of what I would call "hybrid code," and the language itself does nothing to prevent (or even discourage, for that matter) this.