-
January 5th, 2014, 05:20 AM
#1
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.
-
January 5th, 2014, 06:28 AM
#2
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)
-
January 5th, 2014, 02:21 PM
#3
Re: A Question on template
Originally Posted by lucky6969b
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
-
January 5th, 2014, 06:02 PM
#4
Re: A Question on template
Originally Posted by lucky6969b
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|