CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    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 05:25 AM.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: A Question on template

    What is the compile error? Is it to do with '<<'?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

    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
    576

    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
  •  





Click Here to Expand Forum to Full Width

Featured