473,545 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<Eleme nt>::Info* pInfo) {}
};

int main()
{

}
</code snippet>

Aug 20 '07 #1
3 1747
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<Eleme nt>::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<Eleme nt>::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<Eleme nt>::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
11316
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 which is compiled and works fine. ############################################
8
10634
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 template argument for 'TextDB::TextDB_Version', constant expression expected template<int N, char *S> class TextDB_Version
3
2592
by: Ike Naar | last post by:
Given the following C++ snippet: template < typename T > class A { // 1 public : // 2 class AA { } ; // 3 } ; // 4 // 5 template < typename T > class B { // 6 friend class A < T > :: AA ; // 7 } ; // 8
5
2153
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 declaration (template or not) - .hxx files are template impl
7
5936
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 the idea: static int counter = 0; // this variable can be changed only at runtime... template <typename T> struct want_to_be_counted;
3
2719
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 Foo> class Bar { private: Foo foo;
0
1093
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 let's try. The class TSample has a pointer (my smart pointer implementation) to a IList (an indirect list based on the same smart pointers) to the...
8
1968
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; public:
4
3001
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 regards, #include <iostream> template <typename T> struct foo
0
7468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7423
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.