# Question regarding template and union tags

**URL:** <https://forum.opencyphal.org/t/question-regarding-template-and-union-tags/309>\
**Category:** Applications & Usage\
**Created:** [December 22, 2018, 8:34pm UTC](https://forum.opencyphal.org/t/question-regarding-template-and-union-tags/309 "2018-12-22T20:34:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [December 22, 2018, 8:34pm UTC](https://forum.opencyphal.org/t/question-regarding-template-and-union-tags/309/1 "2018-12-22T20:34:26Z")

</div>

Hi!

This is more a C++ general question rather than UAVCAN related. Coming from C language I am a bit new to some C++ features such as templates. However, I am trying to make a function template that needs a union tag to create a uavcan request as below. T and V typenames works, but how can I make the tag a template as well?

```auto
template <typename TAG, typename T, typename V>
myFunction(uavcan_linux::NodePtr& node, [TAG], V& value) {
...
		typename T::Request request;
		request.to<[TAG]>() = value; // Does not work... 
...
}

```

Kind regards

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [December 22, 2018, 8:48pm UTC](https://forum.opencyphal.org/t/question-regarding-template-and-union-tags/309/2 "2018-12-22T20:48:15Z")

</div>

It doesn’t work because in a template context the compiler can’t know the kind of `to`; it doesn’t expect a template instantiation construct ahead. You have to tell the compiler that a template is coming by saying `request.template to<TAG>()`.

In the future, when something isn’t working, please post what exactly the problem is and what error messages you’re seeing, otherwise it might be difficult to understand what’s happening.

---

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [December 22, 2018, 9:32pm UTC](https://forum.opencyphal.org/t/question-regarding-template-and-union-tags/309/3 "2018-12-22T21:32:01Z")

</div>

Yes, will do!  
Thanks for the response, I understand your comment and will redo my work.

Thanks!  
Regards
