Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » class nested Template + inner enum syntaxe
class nested Template + inner enum syntaxe [message #1722601] Sat, 06 February 2016 12:20 Go to next message
teddy smith is currently offline teddy smithFriend
Messages: 8
Registered: May 2015
Junior Member
Hello,

I'm looking some help to find why I have an error. I do my first step with template and I need to solve this case:

If I do this ( with the enum outisde, I have no problem ):


enum class Type{ A , B , C };

template<typename T1>
class Outer
{
     template<typename T2>
	class Inner
    {
        template<Type T3> void f(void);
    };
};

template<typename T1>
	template<typename T2>
		template<Type T3>
void Outer<T1>::Inner<T2>::f(void)
{

};



But I want my enum inside, and with this the code doesn't compile.



template<typename T1>
class Outer
{
    enum class Type{ A , B , C };

    template<typename T2>
	class Inner
    {
        template<Type T3> void f(void);
    };
};

template<typename T1>
	template<typename T2>
		template<typename Outer<T1>::Type T3>
void Outer<T1>::Inner<T2>::f(void)
{

};



The error is "Member déclaration not found". Is someone is able to say me what could be the problem?

Thanks
Re: class nested Template + inner enum syntaxe [message #1722611 is a reply to message #1722601] Sat, 06 February 2016 19:21 Go to previous messageGo to next message
David VavraFriend
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 Go to previous messageGo to next message
teddy smith is currently offline teddy smithFriend
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 #1722627 is a reply to message #1722614] Sun, 07 February 2016 10:46 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Wrong, eh? I didn't know it was an exam or I would have studied more. Sad If by wrong, you mean not quite what you were looking for then OK I suppose. Not at all sure why it "cannot work" unless you mean in the way you intended. BTW: a remarkably similar question was asked almost exactly three years ago at stackoverflow but you may not like that answer either.
http://stackoverflow.com/questions/14776699/defining-an-inner-class-member-function-template-with-a-non-type-enum-argument
As I said earlier, this is OT here.
Re: class nested Template + inner enum syntaxe [message #1722643 is a reply to message #1722627] Sun, 07 February 2016 18:55 Go to previous messageGo to next message
teddy smith is currently offline teddy smithFriend
Messages: 8
Registered: May 2015
Junior Member
no problem, I noted that it is OT forum. I already saw this post. It's almost the same situation. But the example with function doesn't compile. The one with struct works but no use for it to me. I guess I will try another compiler because I quite sure of my syntaxe Sad

Best regards.
Re: class nested Template + inner enum syntaxe [message #1722644 is a reply to message #1722643] Sun, 07 February 2016 19:29 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
OK then. You read the link yet I guess you missed the point of the answer, namely, "... even if [the syntax] was correct, it would not be legal" and the quote from §14.7.3/16 especially the bold part. But, good luck in your compiler shopping anyway.

EDIT: I can't type. I'm just another pretty face around the office.

[Updated on: Sun, 07 February 2016 19:42]

Report message to a moderator

Re: class nested Template + inner enum syntaxe [message #1722646 is a reply to message #1722644] Sun, 07 February 2016 20:46 Go to previous messageGo to next message
teddy smith is currently offline teddy smithFriend
Messages: 8
Registered: May 2015
Junior Member
I guess, the illegal is talking about is the specialisation unless I wrong understood it. I don't need the specialisation for my case. I just need the first part of the example without any specialisation.

Even if I didn't find the exact same example of mine, I didn't read anywhere it's was not possible. You can do it replacing the function by struct so it should work for function.

Thanks for the talk even if it was the wrong forum. I had a wierd error before with Eclipse and ARM cross compiler. The "auto live correct" color claimed one member function was undefined, but the compile is ok and should be ok. but still Eclipse continu to claim an error. So that's why i don't want give up and try later another software with normal compiler not ARM (I know nothing about compiler, this should be good way to learn something useful.)

PS: what does this " I can't type. I'm just another pretty face around the office." mean? I didn't understand. if you answer, can you also say me what is "OT" :S
Re: class nested Template + inner enum syntaxe [message #1722652 is a reply to message #1722646] Sun, 07 February 2016 21:57 Go to previous messageGo to next message
David VavraFriend
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

Re: class nested Template + inner enum syntaxe [message #1722653 is a reply to message #1722652] Sun, 07 February 2016 22:18 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member

Quote:
can you also say me what is "OT" :S

OT is off-topic, not to put words in David's mouth, but I think he was trying to say that this forum is primarily for help using the Eclipse CDT suite of tools and is not a C++ coding forum. Stackoverflow (among others) is a better place for that.

As an OT subject while we are here, I was really surprised that (for me at least) Google did not present OT --> Off Topic in first few results nor as the result of "define OT"!
Re: class nested Template + inner enum syntaxe [message #1722654 is a reply to message #1722652] Sun, 07 February 2016 22:23 Go to previous messageGo to next message
teddy smith is currently offline teddy smithFriend
Messages: 8
Registered: May 2015
Junior Member
I guess that's you whose don't understand.

What I'm doing is not specialisation. It's template non-type parameter which is very different.

To be clear, two simple example.

example 1 : Specialition from template type parameter:

template <typename T> void f(T a){ ... }; <- This one is the primary

specialisation is : template<> void f<int>(int a){ ... };

example 2: Specialisation from non-type parameter:

template <int A> void f(){ ... }; <- This is one a primary, not a specialisation Wink

specialisation is : template <> void f<5>f(){ ... };

If you read again my example, you will see there is no specialisation at all.

///////////////////////////////////////////////////////////////////////////////////////

I just tested with atmel studio . And it works.

So now, i'm pretty sure that my probleme come from my compiler configuration on Eclipse because Atmel and Eclipse use the same ARM thing. I just need to find what it is.

Thanks again for your talk.

Best regards


PS:

so this is not a specialisation, it's primary with two template type parameter and one non type template parameter:

Quote:

template<typename T1>
template<typename T2>
template<typename Outer<T1>::Type T3>
void Outer<T1>::Inner<T2>::f(void)
{};


if it was a specialisation, syntaxe would be:

Quote:

template<typename T1>
template<typename T2>
template<>
void Outer<T1>::Inner<T2>::f<typename Outer<T1>::Type>(void)
{};


Thanks for the explanation of the joke and the "OT".

Best regards,

[Updated on: Sun, 07 February 2016 22:34]

Report message to a moderator

Re: class nested Template + inner enum syntaxe [message #1722753 is a reply to message #1722654] Mon, 08 February 2016 20:39 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Well, I bow to your superior expertise. FWIW: GCC apparently agrees with you and will compile your code example without error or at least without issuing error messages. Whether it's compiles correctly is unknown. This could just be a bug in the Indexer. If you think it is then submit a bug report here: . https://bugs.eclipse.org/bugs/enter_bug.cgi?product=CDT
Re: class nested Template + inner enum syntaxe [message #1722763 is a reply to message #1722753] Mon, 08 February 2016 22:23 Go to previous message
teddy smith is currently offline teddy smithFriend
Messages: 8
Registered: May 2015
Junior Member

I'm pretty sure your are more expert than me. Template can be confuse. But in this case, I guess I'm right until further newcoming Intel :S.

I really appreciate your help. I'll search search a little bit more and try to do it with another software and context again before to claim a bug with Eclipse ( or bad configuration)^^

Thanks again.

Previous Topic:Calculation Error
Next Topic:CDT 8/Indigo: Editor erroneously marks some symbols as unresolved
Goto Forum:
  


Current Time: Thu Mar 28 14:57:20 GMT 2024

Powered by FUDForum. Page generated in 0.03470 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top