Boost logo

Boost Users :

Subject: [Boost-users] some problems about shared_ptr
From: Samurai Deeper (typhoonking77_at_[hidden])
Date: 2010-09-10 09:42:55


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.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net