By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

Template compilation error (Nested class pointer specific)

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.