Template object creation problem

This is a discussion on Template object creation problem within the C++ Programming forums, part of the General Programming Boards category; hi i wnt to create a template object which takes templates as arguments . The below code gives me error ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    32

    Template object creation problem

    hi
    i wnt to create a template object which takes templates as arguments .

    The below code gives me error
    Code:
    length_type nrange = 4;
    typedef Convolution<vsip::Vector,nonsym,support_full> con; 
    Vector<value_type> ran(nrange);
    con c(ran,Domain<1>(nrange));
    The following code compiles(Instead of passing object ,i pass the Vector<value_type)
    Code:
    length_type nrange = 4;
    typedef Convolution<vsip::Vector,nonsym,support_full> con; 
    con c(Vector<value_type>,Domain<1>(nrange));
    how do i create a object of con.
    Last edited by babu198649; 09-14-2008 at 03:56 AM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Code:
    con c(Vector<value_type>,Domain<1>(nrange));
    While this compiles, it doesn't do what you think. It declares a function called "c" that takes a Vector<value_type> as its first and a Domain<1> as its second argument.

    What's the error for the first snippet?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    32
    It declares a function called "c" that takes a Vector<value_type> as its first and a Domain<1> as its second argument.
    Thank u ,i never thought about it.

    The error is
    Code:
    ds.cpp:106: error: no matching function for call to `vsip::Convolution<vsip::Vector,  nonsym,  support_full, vsip::VSIP_DEFAULT_VALUE_TYPE, 0u,  alg_time>::Convolution(vsip::Vector<std::complex<float>, vsip::Dense<1u, std::complex<float>, vsip::tuple<0u, 1u, 2u>, vsip::Local_map> >&, vsip::Domain<1u>)'
    /usr/local/include/vsip/core/signal/conv.hpp:129: note: candidates are: vsip::Convolution<ConstViewT, Symm, Supp, T, N_times, A_hint>::Convolution(const vsip::Convolution<ConstViewT, Symm, Supp, T, N_times, A_hint>&) [with ConstViewT = vsip::Vector, vsip::symmetry_type Symm =  nonsym, vsip::support_region_type Supp =  support_full, T = vsip::VSIP_DEFAULT_VALUE_TYPE, unsigned int N_times = 0u, vsip::alg_hint_type A_hint =  alg_time]
    ../ds.cpp:117:5: warning: no newline at end of file
    make: *** [ds.o] Error 1


    The class Convolution definition is

    Code:
    template <template <typename, typename> class ConstViewT,
    	  symmetry_type                       Symm,
    	  support_region_type                 Supp,
    	  typename                            T = VSIP_DEFAULT_VALUE_TYPE,
    	  unsigned                            N_times = 0,
              alg_hint_type                       A_hint = alg_time>
    class Convolution
      : public impl::profile::Accumulator<impl::profile::signal>,
    #if VSIP_IMPL_REF_IMPL
        public impl::cvsip::Convolution<impl::Dim_of_view<ConstViewT>::dim,
                                        Symm, Supp, float, N_times, A_hint>
    #else
        public impl::dispatcher::Dispatcher<
                 impl::dispatcher::Conv_tag<impl::Dim_of_view<ConstViewT>::dim,
                                            Symm,
                                            Supp,
                                            T,
                                            N_times,
                                            A_hint> >::backend_type
    #endif
    {
      // Implementation compile-time constants.
    private: 
      static dimension_type const dim = impl::Dim_of_view<ConstViewT>::dim;
    
      typedef impl::profile::Accumulator<impl::profile::signal> accumulator_type;
    
    #if VSIP_IMPL_REF_IMPL
      typedef impl::cvsip::Convolution<impl::Dim_of_view<ConstViewT>::dim,
                                       Symm, Supp, float, N_times, A_hint> base_type;
    #else
      typedef typename impl::dispatcher::Dispatcher<
                       impl::dispatcher::Conv_tag<dim,
                                                  Symm,
                                                  Supp,
                                                  T,
                                                  N_times,
                                                  A_hint> >::backend_type base_type;
    #endif
    
    public:
      template <typename Block>
      Convolution(ConstViewT<T, Block> filter_coeffs,
    	      Domain<dim> const&   input_size,
    	      length_type          decimation = 1)
        VSIP_THROW((std::bad_alloc))
          : accumulator_type(impl::signal_detail::Description<dim, T>::tag
                             ("Convolution",
                              impl::extent(impl::conv_output_size
                                           (Supp, view_domain(filter_coeffs), 
                                            input_size, decimation)),
                              impl::extent(filter_coeffs)),
                             impl::signal_detail::Op_count_conv<dim, T>::value
                             (impl::extent(impl::conv_output_size
                                           (Supp, view_domain(filter_coeffs),
                                            input_size, decimation)),
                              impl::extent(filter_coeffs))),
            base_type(filter_coeffs, input_size, decimation)
      {
        assert(decimation >= 1);
        assert(Symm == nonsym ? (filter_coeffs.size() <=   input_size.size())
    			  : (filter_coeffs.size() <= 2*input_size.size()));
      }

    The Vector definition is
    Code:
    template <typename T, typename Block>
    class Vector : public vsip::impl_View<vsip::Vector,Block>
    {
      typedef vsip::impl_View<vsip::Vector,Block> impl_base_type;
      typedef typename impl::Lvalue_factory_type<Block>::type impl_factory_type;
    
    public:
      // Compile-time values.
      static dimension_type const dim = 1;
      typedef Block                                      block_type;
      typedef typename block_type::value_type            value_type;
      typedef typename impl_factory_type::reference_type reference_type;
      typedef typename impl_factory_type::const_reference_type
    		const_reference_type;
    
    private:
      // Implementation compile-time values.
      typedef typename block_type::map_type             impl_map_type;
    
      // [view.vector.subview_types]
      // Override subview_type and make it writable.
      typedef impl::Subset_block<block_type> impl_subblock_type;
    
    public:
      typedef Vector<T, impl_subblock_type>      subview_type;
    
      // [view.vector.constructors]
      Vector(length_type len, T const& value,
    	 impl_map_type const& map = impl_map_type())
        : impl_base_type(len, value, map, impl::disambiguate)
      {}

    EDIT:- Complete definition is at http://www.codesourcery.com/public/v...nce/index.html
    click vsip in the left coloum and then sources for Convolution in the right coloumn.
    Last edited by babu198649; 09-14-2008 at 04:15 AM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Hm, are you sure you're allowed to omit the second template argument to Vector when creating the instance?

    Anyway, the error message says that it doesn't recognize the constructor. Which is weird. It could be a shortcoming of the compiler in template parameter deduction, but I don't think it is.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    32
    yes

    Actually there are many constructors for Vector,i wanted to show the template arguments and hence i have not shown the Vector i have used.

    The below constructor is one of the Vectors constructor which i have used.

    Code:
    explicit Vector(length_type len,
    	          impl_map_type const& map = impl_map_type())
        : impl_base_type(len, map)
      {}

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I was wondering about the template arguments, since Vector has two, but you supply only one. But there seems to be a declaration with a default around.

    What GCC version do you use? 4.1.2 correctly compiles this little test case:
    Code:
    #include <iostream>
    
    template <template <typename, typename> class T>
    struct Foo
    {
            template <typename U>
            Foo(T<int, U>) { std::cout << "Yep!\n"; }
    };
    
    template <typename T, typename U>
    struct Bar
    {
    };
    
    int main()
    {
            Bar<int, float> b;
            Foo<Bar> f(b);
    }
    Last edited by CornedBee; 09-14-2008 at 05:13 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    32
    i use gcc 3.4.4.But i have compiled u r code and it worked.Is the error with the Convolution class

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    32
    Thanks to all
    i have found the error,As we can see in the below template definition the typename T is assigned with the default type( T = VSIP_DEFAULT_VALUE_TYPE/*typedef of float */ ).
    Code:
    template <template <typename, typename> class ConstViewT,
    	  symmetry_type                       Symm,
    	  support_region_type                 Supp,
    	  typename                            T = VSIP_DEFAULT_VALUE_TYPE,
    	  unsigned                            N_times = 0,
              alg_hint_type                       A_hint = alg_time>
    class Convolution
    ......
    But i was using value_type(typedef of complex) to create Vector object and used it to create Convolution object.
    so instead of using the default argument( T = VSIP_DEFAULT_VALUE_TYPE) by the compiler when i forced it to use value_type(typedef of complex),by passing value_type as the replacement of the default argument to the compiler it worked.
    Below is the working code(see the 4th parameter)

    Code:
    length_type nrange = 4;
    typedef Convolution<vsip::Vector,nonsym,support_full,value_type> con; 
    Vector<value_type> ran(nrange);
    con c(ran,Domain<1>(nrange));
    Last edited by babu198649; 09-16-2008 at 04:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 05:13 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21