Re: [QuantLib-svn] SF.net SVN: quantlib:[11264] trunk/QuantLib/ql/termstructures/volatilities /caplet

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [QuantLib-svn] SF.net SVN: quantlib:[11264] trunk/QuantLib/ql/termstructures/volatilities /caplet

DU VIGNAUD DE VILLEFORT FRANCOIS GASAPRD PHI

>It is, but (I think) only on the type of an argument. What did you have
>in mind?


Here is an example of the code I tried to write:  

class X {};
class Y: public X {};

class A {
  public:
    template <class T>
    A():p_(){
        p_ = shared_ptr(new T);
    }
  private:
      shared_ptr<X> p_;
};


void main() {
    shared_ptr<A> a (new A<X>());
}


François



----------------------------------------

Can't act. Slightly bald. Also dances.
-- RKO executive, reacting to Fred Astaire's screen test.
Cerf/Navasky, "The Experts Speak"



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: [QuantLib-svn] SF.net SVN: quantlib:[11264] trunk/QuantLib/ql/termstructures/volatilities /caplet

Luigi Ballabio
On Thu, 2007-06-07 at 18:31 +0200, DU VIGNAUD DE VILLEFORT FRANCOIS
GASAPRD PHI wrote:

> Here is an example of the code I tried to write:  
>
> class A {
>   public:
>     template <class T>
>     A() { ... }
> };
>
>
> void main() {
>     shared_ptr<A> a (new A<X>());
> }

It doesn't work. The compiler parses A<X>() as the constructor of a
template class A, not the template constructor of a class A.
You can write template constructors, but only in cases such as:

class A {
  public:
    template <class T>
    A(const T& t) { ... }
};

void main() {
    X x;
    shared_ptr<A> a (new A(x));
}

where the <X> is not there and the template specialization is deduced
from the type of the argument.

What were A and X?

Later,
        Luigi


----------------------------------------

There's no sense in being precise when you don't even know what you're
talking about.
-- John von Neumann



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev