473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1740
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Vinokur | last post by:
========================================= Windows 2000 CYGWIN_NT-5.0 1.3.22(0.78/3/2) GNU gcc version 3.2 20020927 (prerelease) ========================================= Here is some program...
8
by: Kevin Grigorenko | last post by:
Hello all, Okay, I've got a templated class that that takes an int and a char *, but when I try to instantiate an object of that template, VS.NET complains with: error C2975: 'S' : invalid...
3
by: Ike Naar | last post by:
Given the following C++ snippet: template < typename T > class A { // 1 public : // 2 class AA { } ; // 3 } ; ...
5
by: Nomak | last post by:
Hello all, i have two template classes which needs each other. I tried to write some fwd decl / decl / impl in a good way but i can't get it to compile. Explanations: - .hh files are for...
7
by: Patrick Kowalzick | last post by:
Dear all, I just wondered if it is possible to count the number of classes created via a template class at compile time. To show what I mean I post an example, which is not working but carries...
3
by: case2005 | last post by:
Can anyone help with the following, I don't know if it's possible, but I'm certain there must be a standard way of dealing with this. I have the following: template<typename FooBar, typename...
0
by: Adriano Coser | last post by:
Hello. I'm trying to compile a DLL with Visual C++ .NET 2003 and I'm facing an error declaring template variables with prototypes. I don´t know if I'll be able to explain my scenario, but...
8
by: flamexx7 | last post by:
Can anybody tell me what is wrong with declaration of pointer p ? template<class Tclass Stack { struct Link { T* data; Link* next; Link(T* dat, Link* nxt) : data(dat), next(nxt) {} }* head;...
4
by: Ares Lagae | last post by:
How is an output stream operator of a class nested in a class template defined? The code fragment below does not compile. Maybe it's just me, but I don't see why it should not compile. Best...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.