|
Re: What if Constant Values were also valid Types?
|
Posted: Jan 20, 2006 9:50 AM
|
|
> Ok, as I understand from your posting, now, when > inheriting using "const", you only inherit the > "const" member functions? It was a little hard to > tell, as your example didn't describe the semantics of it.
Sorry, now, that I look at that example of mine, maybe it really isn't so clear. If someone doesn't get it yet, line > public const Rectangle is crucial. 'const' keyword here means inheriting only accessors and constructors, and makes const Rectangle supertype of Square, but doesn't make Rectangle supertype of square.
> It may matter less, as this was just an example, > but Square may end up with redundant data, this > way (both width and height).
You are talking about inheritance of implementation. I like to completely separate it from subtyping. My example is about subtyping, not about inheritance of implementation (which is completely different story).
> You're inheriting getWidth() and getHeight(), > which, for a Square, always will be the same, and > you add getSize() in the derived class. In short, you > get a bloated interface, so as an example of the > usefulness of the proposed feature, I don't think t > his is a good one.
I don't see what's wrong with square having GetHeight and GetWidth. Usually, when subtyping is concerned, you get huge interfaces. This can be solved by the language by introducing renaming and namespaces for class methods.
> Yes, but I provided an example to get the same effect, > without the uglyness.
Sorry, I wrote wrong thing. I think your example (with ConstRectangle) is ugly, and I think mine with const Rectangle is elegant.
> but just making an object const doesn't usually > _remove_ functionality (it'll give an error if you > call a non-const member function, but it's still there).
This is either a very strange argument, or I don't understand what you are saying.
> In short, I don't understand the advantage of this,
How's about that example with templated IsGreater()? You can't do that with ConstRectangle. I have some other advantages in mind, but they require long discussion. In short, I think that I would be able to argue that 'const inheritance' avoids code duplication.
Also, I have a feeling that you didn't understand point b). Let me try to explain this way. Using my example, you can use types Rectangle and const Rectangle. Using your example, you can use types Rectangle and ConstRectangle. So it looks to me like you are against 'const' keyword here.
Also, I noticed an error im one of my previous posts about type 42. The code should go:
const Int &a=42; // a.isPrime(); //calls 42::isPrime 42.isPrime(); //same as above
If you look at previous post of mine containing this example, you will see that it uses 'const inheritance'.
To conclude, we simply have different opinions. I said my arguments, you said yours. If there is still something unclear, I will be pleased to clarify.
|
|