Fluent interfaces and inheritance in C++ -


I want to create a base (abstract) (let's call it type :: base ) With the usual FonseyaNanti and a fluent interface, the problem I am facing is the return type of all the methods

  class base {public: base (); Virtual ~ (base); In the base & amp; With_foo (); In the base & amp; With_bar (); Protected: // whatever ...};  

I can now subtype, e.g.:

pre- class my_type: public base {public: myType (); // more methods ...};

The problem is that while using these subtypes:

  my_type build_my_type () {my_type (). Return_foo (). With_bar (); }  

This will not compile because we are returning the base instead of my_type.

I know that I only:

  my_type build_my_type () {my_type ret; . Ret.with_foo () with_bar (); Return writ; }  

But I was wondering how can I apply it, and I have not got any reasonable ideas, some suggestions?

This type of "losing type" problem can be resolved with templates - but it is more complex .

Example.

  class pizza {string topping; Public: Virtual double price () const; }; Template & lt; Square t, class base & gt; Class Fluent Pieza: {... some implementation with public base {T * anchovies (...);}; }; Class Recta Pizza: Public Fluent PGA & Lt; Recta pizzas, pizzas & gt; {Double price () const {return length * width; :)}}; Class Square Pizza: Public Fluent Pizza & Lt; Square Pizza, Rect Pizzes & gt; {    ... anything else ... };  

You can then

  squarepage * p = (new squarepage) - & gt; Can write with anchovies ();             Class T: Public Fluent & lt; T, B & gt;  

A perspective interface can not be used on another perspective object, but instead at pointers:

  class pizza {...}; Square RectPizza {...}; Class Square pizza ... ... you can imagine ...}; Template & lt; Class T & gt; Class Fluent Pejopet {T * Pizza; Public: FluentPizzaPtr withAnchovies () {Pizza-> Adivatives (); // A seamless withdrawal method; }};  

Use this way:

  FlintPagepet & lt; Squarepage & gt; SquarePizzaFactory () {...} FluentPassipster & lt; Square Pizzia & gt; MyPizza = squarePizzaFactory () withAnchovies () .;  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -