471,351 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,351 software developers and data experts.

Template compilation error (Nested class pointer specific)

hi,

I am facing compilation error for following snippet:
Compilation Error:
t7.cc:17: error: expected `)' before '*' token
<code snippet>
#include <iostream>

template <typename Element>
class Sort
{
public:
class Info
{
public:
Info() {}
};

public:
=========== Error Line.
Error seems to occur only when we try to use pointer/reference to Info
class. Shockingly, if this pointer is second parameter error vanishes.
(Sort(uint32_t i, Sort<Element>::Info* pInfo) works)
Sort(Sort<Element>::Info* pInfo) {}
};

int main()
{

}
</code snippet>

Aug 20 '07 #1
3 1604
krunalb wrote:
>
<code snippet>
#include <iostream>

template <typename Element>
class Sort
{
public:
class Info
{
public:
Info() {}
};

public:
=========== Error Line.
Error seems to occur only when we try to use pointer/reference to Info
class. Shockingly, if this pointer is second parameter error vanishes.
(Sort(uint32_t i, Sort<Element>::Info* pInfo) works)
Sort(Sort<Element>::Info* pInfo) {}
You are missing a typename:

Sort(typename Sort<Element>::Info* pInfo) {}
--
Ian Collins.
Aug 20 '07 #2
On Aug 20, 3:08 pm, krunalb <krunalbaus...@gmail.comwrote:
hi,

I am facing compilation error for following snippet:

Compilation Error:
t7.cc:17: error: expected `)' before '*' token

<code snippet>
#include <iostream>

template <typename Element>
class Sort
{
public:
class Info
{
public:
Info() {}
};

public:
=========== Error Line.
Error seems to occur only when we try to use pointer/reference to Info
class. Shockingly, if this pointer is second parameter error vanishes.
(Sort(uint32_t i, Sort<Element>::Info* pInfo) works)
Sort(Sort<Element>::Info* pInfo) {}
Sort(typename Sort<Element>::Info* pInfo) {}

BTW no need to specify the template parameter and the name of the
enclosing class.
i.e. Sort(Info* pInfo) {}
will also work.

-N

Aug 20 '07 #3
krunalb wrote:
hi,

I am facing compilation error for following snippet:
Compilation Error:
t7.cc:17: error: expected `)' before '*' token
<code snippet>
#include <iostream>

template <typename Element>
class Sort
{
public:
class Info
{
public:
Info() {}
};

public:
=========== Error Line.
Error seems to occur only when we try to use pointer/reference to Info
class. Shockingly, if this pointer is second parameter error vanishes.
(Sort(uint32_t i, Sort<Element>::Info* pInfo) works)
Sort(Sort<Element>::Info* pInfo) {}
This works:
Sort( typename Sort<Element>::Info * pInfo) {}

This works too:
Sort( Info * pInfo) {}

.... In general, you need to use "typename" when spefifying a type like
you have unless it is already specified as type (like class Info).

};

int main()
{

}
</code snippet>
Aug 20 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Kevin Grigorenko | last post: by
3 posts views Thread by Ike Naar | last post: by
7 posts views Thread by Patrick Kowalzick | last post: by
reply views Thread by Adriano Coser | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.