CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] a type (typename) as a parameter of a function

  1. #1
    Join Date
    Dec 2008
    Posts
    54

    [RESOLVED] a type (typename) as a parameter of a function

    Hi! May be somebody could explain or give a reference on how to use a type as a function parameter. I am using the deal.II library. There is next member function there:
    Code:
    template<int dim>
    template<typename InputVector, class DH>
    static void KellyErrorEstimator< dim >::estimate(const Mapping< dim > & mapping,
    		const DH & dof,
    		const Quadrature< dim-1 > & quadrature,
    		const typename FunctionMap< dim >::type & neumann_bc,
    		const InputVector & solution,
    		Vector< float > & error,
    		const std::vector< bool > & component_mask = std::vector< bool >(),
    		const Function< dim > *  	coefficients = 0,
    		const unsigned int  	n_threads = multithread_info.n_default_threads,
    		const unsigned int  	subdomain_id = numbers::invalid_unsigned_int,
    		const unsigned int  	material_id = numbers::invalid_unsigned_int	 
    	) 			[inline, static]
    For my question parameter const typename FunctionMap< dim >::type & neumann_bc is important. The declaration of its type is
    Code:
    typedef std::map<unsigned char, const Function<dim>*> FunctionMap< dim >::type
    I undestand it as the reference to the name of the type is given to the function as a parameter. Is it possible to use a type or its reference as a parameter? This structure is compiled perfectly in the next configuration
    Code:
    typename FunctionMap<dim>::type neumann_boundary;
    KellyErrorEstimator<dim>::estimate (dof_handler, dealii::QGauss<dim-1>(feq1+1), neumann_boundary, solution, estimated_error_per_cell);
    Here we are creating an object neumann_boundary of the type "type map".
    However, if i change it to
    Code:
    typedef FunctionMap<dim>::type neumann_boundary;
    or
    Code:
    typedef typename FunctionMap<dim>::type neumann_boundary;
    i got an error. So, what's going on when one transfers to a function a type as a parameter?

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: a type (typename) as a parameter of a function

    You can't pass a type as an actual argument, you can only pass an object of a given type.

    I undestand it as the reference to the name of the type is given to the function as a parameter.
    No, a reference to an object of that type is given to the function as a parameter.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #3
    Join Date
    Dec 2008
    Posts
    54

    Re: a type (typename) as a parameter of a function

    Thank you for answer, and sorry for asking such a stupid question. Just something wrong is today with my head.
    Last edited by StudentFS; January 8th, 2009 at 05:48 PM.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: a type (typename) as a parameter of a function

    Quote Originally Posted by StudentFS View Post
    Thank you for answer, and sorry for asking such a stupid question. Just something wrong is today with my head.
    There is no such thing as a stupid question.....there are only stupid answers (and these are usually my part).

    Jokes aside....that is why the forum exists....don't hesitate to ask anything just because you might think it would be stupid....

  5. #5
    Join Date
    Dec 2008
    Posts
    54

    Re: a type (typename) as a parameter of a function

    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)