some problems about shared_ptr
I am a newbie of C++ and I have some question about the shared_ptr I think the best way to explain it is with an example: /*******beginning of CValue.h*************/ #ifndef TVALUE_H #define TVALUE_H template< typename tvalue > class CValue { public: CValue( tvalue value ) : value_(value) {}; private: tvalue value_; }; #endif /****end*************/ /*****Type.h***********/ #ifndef TYPE_H #define TYPE_H #include<boost/shared_ptr.hpp> /*template< typename tvalue > struct Type{ typedef boost::shared_ptr< CValue< tvalue > > pValue; };*/ template<typename T, template <typename> class Value> struct Type { typedef boost::shared_ptr< Value<T> > pValue; }; #endif /********end************/ what if I want to make it as a composition class? by example /***************example**********/ #include "Type.h" #include "CValue.h" template<typename T> class DIP //digital image processing { public: DIP(); virtual ~DIP(); shared_ptr < Type<T, filter> >createMediumFilter(); }; template<typename T> DIP<T>::DIP() {} template<typename T> DIP<T>::~DIP() {} template<typename T> shared_ptr< Type<T, filter> > DIP<T>::createMediumFilter() { typename Type<T, filter>::pValue c(new mediumFilter< T >); return c; } /*****************end**************/ I want to create the instance of mediumFilter like this in the main function int main() { Type<matrix<double>, Composition>::pValue C(new Composition<matrix<double>
); Type<matrix<double>, CValue>::pValue D; D = C->createCValue();
cout<<"system pause"<<endl; cin.get(); } how could I fix the problems? thanks -- View this message in context: http://old.nabble.com/some-problems-about-shared_ptr-tp29674340p29674340.htm... Sent from the Boost - Users mailing list archive at Nabble.com.
AMDG Samurai Deeper wrote:
I am a newbie of C++ and I have some question about the shared_ptr I think the best way to explain it is with an example:
/*******beginning of CValue.h*************/ <snip> /****end*************/
/*****Type.h***********/
<snip>
template<typename T, template <typename> class Value> struct Type { typedef boost::shared_ptr< Value<T> > pValue; };
What is the point of Type? It appears to be gratuitous complexity to me.
/********end************/
what if I want to make it as a composition class?
What do you mean by a composition class?
by example
/***************example**********/ #include "Type.h" #include "CValue.h"
template<typename T> class DIP //digital image processing { public: DIP(); virtual ~DIP(); shared_ptr < Type<T, filter> >createMediumFilter(); };
What is filter here? Also, did you mean the Type<T, filter>::pValue, aka shared_ptr<filter<T> >?
<snip> /*****************end**************/
I want to create the instance of mediumFilter like this in the main function
int main() { Type<matrix<double>, Composition>::pValue C(new Composition<matrix<double>
);
Type<matrix<double>, CValue>::pValue D; D = C->createCValue();
cout<<"system pause"<<endl; cin.get(); }
how could I fix the problems
I've read through this several times, and I'm afraid that I don't understand what you're trying to do. In Christ, Steven Watanabe
sorry, I forgot to change the names of those classes. I am deeply sorry for my unconscious /***********CValue**********/ template< typename tvalue > class CValue { public: CValue( tvalue value ) : value_(value) {}; private: tvalue value_; }; /***********end of CValue*********/ /***********Type**************/ template<typename T, template <typename> class Value> struct Type { typedef boost::shared_ptr< Value<T> > pValue; }; /********end of Type************/ /**********Composition**********/ template<typename T> class Composition //digital image processing { public: Composition(); virtual ~Composition(); shared_ptr< T > createCValue(); }; template<typename T> Composition<T>::Composition() {} template<typename T> Composition<T>::~Composition() {} template<typename T> shared_ptr< T > Composition<T>::createCValue() { typename Type<T, CValue>::pValue c(new Composition< T >); return c; } /*********end of composition***********/ /**********main************/ int main() { Type<matrix<double>, Composition>::pValue C(new Composition<matrix<double>
); Type<matrix<double>, CValue>::pValue D; D = C->createCValue();
cout<<"system pause"<<endl; cin.get(); } /*********end of main********/ I hope I could create the instance of CValue through class Composition so I wrote a "createCvalue" function in the class Composition -- View this message in context: http://old.nabble.com/some-problems-about-shared_ptr-tp29674340p29682576.htm... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Samurai Deeper
-
Steven Watanabe