Help with shared_ptr and template

Hello: I have this problem and I do not how to fix it, I know I cannot write template typedefs, its a limitiation of the C++ syntax, right? or I'm wrong? I saw that the best way is to wrap your typedefs in a struct, which can be templated, but I'm still stack with problems. The best way to explain it's with an example: #include <cstdlib> #include <iostream> #include <boost/shared_ptr.hpp> template< typename tvalue > class CValue { public: CValue( tvalue value ) : value_(value) {}; private: tvalue value_; }; template< typename tvalue > struct Type{ typedef boost::shared_ptr< CValue< tvalue > > pValue; }; int main(int argc, char *argv[]) { Type<bool>::pValue a; return EXIT_SUCCESS; } How can I create a shared_ptr for the template class "CVALUE"?? Please I do not know what else I can prove... :( Thank you.. Mario.. Salu2...

On Tue, Jan 27, 2009 at 7:24 PM, Mario Chacon <the.masch@gmail.com> wrote:
Hello: I have this problem and I do not how to fix it, I know I cannot write template typedefs, its a limitiation of the C++ syntax, right? or I'm wrong? I saw that the best way is to wrap your typedefs in a struct, which can be templated, but I'm still stack with problems. The best way to explain it's with an example:
#include <cstdlib> #include <iostream> #include <boost/shared_ptr.hpp>
template< typename tvalue > class CValue { public: CValue( tvalue value ) : value_(value) {};
private: tvalue value_; };
template< typename tvalue > struct Type{ typedef boost::shared_ptr< CValue< tvalue > > pValue; };
int main(int argc, char *argv[]) { Type<bool>::pValue a;
return EXIT_SUCCESS; }
How can I create a shared_ptr for the template class "CVALUE"?? Please I do not know what else I can prove... :(
Your code seems to compile fine, what's the problem? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

AMDG Mario Chacon wrote:
I have this problem and I do not how to fix it, I know I cannot write template typedefs, its a limitiation of the C++ syntax, right? or I'm wrong? I saw that the best way is to wrap your typedefs in a struct, which can be templated, but I'm still stack with problems. The best way to explain it's with an example:
<snip working code>
How can I create a shared_ptr for the template class "CVALUE"?? Please I do not know what else I can prove... :(
I'm not sure what you're asking. Your code compiles for me and the type of "a" is shared_ptr<CValue<bool> >? What am I missing? In Christ, Steven Watanabe

replace Type<bool>::pValue a; with typename Type<bool>::pValue a; ? B/Rgds Max Hello: I have this problem and I do not how to fix it, I know I cannot write template typedefs, its a limitiation of the C++ syntax, right? or I'm wrong? I saw that the best way is to wrap your typedefs in a struct, which can be templated, but I'm still stack with problems. The best way to explain it's with an example: #include <cstdlib> #include <iostream> #include <boost/shared_ptr.hpp> template< typename tvalue > class CValue { public: CValue( tvalue value ) : value_(value) {}; private: tvalue value_; }; template< typename tvalue > struct Type{ typedef boost::shared_ptr< CValue< tvalue > > pValue; }; int main(int argc, char *argv[]) { Type<bool>::pValue a; return EXIT_SUCCESS; }

Thank you for answer me, but the thing is I cannot get what I need. How can I create an pValue object with different type?? because in my test It does not create a sharer_ptr of CVALUE specified in bool value. Do you know what I mean?? Thank you ... On Wed, Jan 28, 2009 at 2:20 AM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
Max wrote:
replace
Type<bool>::pValue a;
with
typename Type<bool>::pValue a;
typename is illegal outside of templates.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Template template parameters? template<typename T, template <typename> class Value> struct Type{ typedef boost::shared_ptr< Value<T> > pValue; }; int main(int argc, char *argv[]) { Type<bool, CValue>::pValue a; return EXIT_SUCCESS; } Andrew Sutton andrew.n.sutton@gmail.com

Great !! These is it exactly what I need!!.. You rocks men!!... Thank you for all!!... Mario Salu2... On Wed, Jan 28, 2009 at 11:01 AM, Andrew Sutton <andrew.n.sutton@gmail.com>wrote:
Template template parameters?
template<typename T, template <typename> class Value> struct Type{ typedef boost::shared_ptr< Value<T> > pValue; };
int main(int argc, char *argv[]) { Type<bool, CValue>::pValue a;
return EXIT_SUCCESS; }
Andrew Sutton andrew.n.sutton@gmail.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

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/Help-with-shared_ptr-and-template-tp21699259p29676966.... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (6)
-
Andrew Sutton
-
Emil Dotchevski
-
Mario Chacon
-
Max
-
Samurai Deeper
-
Steven Watanabe