Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Partially c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 9499 of 9807
Post > Topic >>

Re: Partially complete types

by Vidar Hasfjord <vattilah-groups@[EMAIL PROTECTED] > Apr 16, 2008 at 03:57 AM

On Apr 15, 4:26 am, Greg Herlihy <gre...@[EMAIL PROTECTED]
> wrote:
> Instead, the Library interface should declare IParameter along these
> lines:
>     class Component
> [...]
>        virtual IParameter* get_parameter ();
> [...]
>     class ComponentImpl : public Component
>        virtual Parameter* get_parameter ()

Yep, this will work due to covariant return types, which allows you to
strengthen the type info. But it is a lot of scaffolding.

A simpler solution is to just create two interfaces; one for external
use and one for internal use:

   class Component {
   public:
     class IParameter {...};
     virtual IParameter* get_parameter ();
   private:
     class Parameter;
     Parameter* private_get_parameter ();
     ...
   };

Implementation:

   class Component::Parameter : Component::IParameter {
     ...
   };
   IParameter* Component::get_parameter ()
     {return private_get_parameter ();}

This works and has less implications on the Component class hierarchy
compared to your solution. But it is still scaffolding. The interface
of Component is duplicated and one implemented in terms of the other.
It would be much more straight-forward to be able to tell the compiler
partial type information. Here's that hypothetical solution again:

   class Component {
   public:
     class IParameter {...};
     class Parameter : public IParameter; // partial type completion
     virtual Parameter* get_parameter ();
   private:
     ...
   };

But is it possible/easy to implement? Does the compiler know enough
after seeing the partial type to use Parameter through the base class
IParameter?

Regards,
Vidar Hasfjord

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 6 Posts in Topic:
Partially complete types
Vidar Hasfjord <vattil  2008-04-14 12:51:07 
Re: Partially complete types
"Alf P. Steinbach&qu  2008-04-14 21:23:05 
Re: Partially complete types
Greg Herlihy <greghe@[  2008-04-14 21:26:22 
Re: Partially complete types
Marcin Swiderski <sfid  2008-04-15 23:21:48 
Re: Partially complete types
Vidar Hasfjord <vattil  2008-04-16 03:57:21 
Re: Partially complete types
Vidar Hasfjord <vattil  2008-04-16 03:58:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 19 20:06:25 CDT 2008.