|
Re: class nested Template + inner enum syntaxe [message #1722611 is a reply to message #1722601] |
Sat, 06 February 2016 19:21 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
This is a question better asked at stackoverflow.com as it is OT for this forum which is to answer CDT related questions.
Not sure what template<Type T3> would mean. The following seems to work though. Substitute A,B,C as needed for T3. Actually, they will likely need to be qualified with Outer<T1>::Type so A would be expressed as Outer<T1>::Type::A. See an example of this in the definition for g.
template<typename T1>
class Outer
{
enum class Type{ A , B , C };
template<typename T2>
class Inner
{
template<typename T3> void f(void);
template<typename T3> void g(void);
};
};
template<typename T1>
template<typename T2>
template<typename T3>
void Outer<T1>::Inner<T2>::f<T3>(void)
{
};
template<typename T1>
template<typename T2>
template<typename T3>
void Outer<T1>::Inner<T2>::g<T3>(void)
{
int w = Outer<T1>::Type::A;
};
EDIT:
I removed some extraneous statements.
Also, I should emphasize I'm pretty sure what template<Type T3> means but I'm not sure what your intended meaning is. There are a bunch of gotchas in nested templates. You might want to read the template FAQ at https://isocpp.org/wiki/faq/templates#
perhaps in particular https://isocpp.org/wiki/faq/templates#nondependent-name-lookup-types and a couple of the surrounding ones. I think in your case, you just need to add proper qualification.
Again, interesting though it may be, this is OT and I'm only posting things to ponder about before going to stackoverflow or an equivalent and not to delve into the subject.
[Updated on: Sat, 06 February 2016 22:13] Report message to a moderator
|
|
|
Re: class nested Template + inner enum syntaxe [message #1722614 is a reply to message #1722611] |
Sat, 06 February 2016 22:15 |
teddy smith Messages: 8 Registered: May 2015 |
Junior Member |
|
|
unfortunatly, "template<Type T3>" was on purpose. I can not replace it by "template<typename T3>" which has another meaning.
My third nested template need to be a non-type template parameter which in this case is "Type" (an arbritraty name came from enum class Type).
Thanks, I'll try to ask on stackoverflown on your advice.
Edit: Your code can not work. Your defination of g and f, you don't have the right to put
.................. void Outer<T1>::Inner<T2>::f<T3>(void)
but it should be
.................. void Outer<T1>::Inner<T2>::f(void).
My aim is to be make possible to write something like this :
IO<GPIOA_BASE>::SET<PIN_A0>::AsDigitalOutput<IO::PullType::floating>();
it works, but my enum class is outside, because I still didn't find the right syntaxe when I put them inside my class.
Best regards.
[Updated on: Sat, 06 February 2016 22:49] Report message to a moderator
|
|
|
|
|
|
|
Re: class nested Template + inner enum syntaxe [message #1722652 is a reply to message #1722646] |
Sun, 07 February 2016 21:57 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
Not to beat this to death but I suspect you don't understand the issue,
You say you don't need specialization but tried to do it anyway with
template<typename T1>
template<typename T2>
template<typename Outer<T1>::Type T3>
void Outer<T1>::Inner<T2>::f(void)
{};
The rules (that pesky §14.7.3/16) are that specialization must start at the outer level (one of those gotchas I mentioned previously) but you only want to specialize the innermost level.Whether you are aware of it or not, template<typename Outer<T1>::Type T3> is a specialization, You are attempting to define a template function that is specific to T3 being one of the enumerations. Being specific is what is meant by the term specialization. It helps to know the semantics as well as the syntax.
The really pertinent part of §14.7.3/16: the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well. That you can do this anyway with an external type (i.e., a type outside of all of the template levels) is interesting. Maybe the rule has been changed for this particular case or it is one of those extra features that could cause grief further down the road. I do note that Codan accepts this too,
Your post here and that at stackoverflow are nearly identical with the only differences being the number of template levels and function name. The problem is the same. Why you think the answers there have nothing to do with your problem is beyond me. If you need further help with this, please go to stackoverflow (or perhaps an equivalent forum) and ask there. If you don't understand the answers then ask for clarification first-hand instead of by proxy.
EDIT re: pretty face
Sexism in the office: the gorgeous secretary was hired for her looks. She can't type and is just a pretty face around the office.
The joke is: I'm not female and hardly pretty. No one would hire me for my looks. But I still can't type.
[Updated on: Sun, 07 February 2016 22:12] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds