A Question on template
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: A Question on template

  1. #1
    Join Date
    Dec 2010
    Posts
    589

    A Question on template

    What my purpose here is to use a template
    to append an item of type T to a node of a ptree (boost)


    Code:
    template<typename T>
    ptree& stick(ptree& tree, char *location, T const & t)
    {
     
        return tree.add(location, t);
      
    }
    Here I can't compile

    Code:
    struct hdr {
    	WORD weights_per_vertex;
    	WORD weights_per_face;
    	WORD num_bones;
    };
    hdr h;
    h.weights_per_vertex = numMax;
    h.weights_per_face = 0;
    h.num_bones = numAffect;
     
    ptree& skinHeader = stick(stored, "", h);
    Doesn't the type of T includes the type struct hdr?

    Thanks
    Jack
    Last edited by lucky6969b; January 5th, 2014 at 04:25 AM.

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,308

    Re: A Question on template

    What is the compile error? Is it to do with '<<'?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,424

    Re: A Question on template

    Quote Originally Posted by lucky6969b View Post
    Here I can't compile
    Why didn't you post the compiler error?
    Code:
    struct hdr {
    	WORD weights_per_vertex;
    	WORD weights_per_face;
    	WORD num_bones;
    };
    I have never used "ptree", but without the compiler error posted, we have no idea if the error is syntax related, whether ptree.add() requires the third parameter to have certain characteristics (i.e. whether the type is streamable), who knows...

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Jul 2013
    Posts
    243

    Re: A Question on template

    Quote Originally Posted by lucky6969b View Post
    Doesn't the type of T includes the type struct hdr?
    I don't know what you mean by that but you can always specify the generic type like,

    ptree& skinHeader = stick<hdr>(stored, "", h);

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center