473,402 Members | 2,064 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,402 software developers and data experts.

Problem with template

When I try to compile this template I get an error in the line:

"enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};"

saying:

blop.hpp:8: error: expected primary-expression before ‘>’ token
#ifndef BLOP_HPP_
#define BLOP_HPP_
template<typename T>
class IsClassT {
public:
enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};
enum { No = !Yes};
//int getInt(){return a;};

private:
typedef char One;
typedef struct { char a[2];} Two;
template<typename Cstatic One test(int C::*);
template<typename Cstatic Two test();
static const int a = 10;
};

Any ideas why I get this error?
May 7 '07 #1
3 1979

"desktop" <ff*@sss.comwrote in message
news:f1**********@news.net.uni-c.dk...
When I try to compile this template I get an error in the line:

"enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};"

saying:

blop.hpp:8: error: expected primary-expression before ‘>’ token
#ifndef BLOP_HPP_
#define BLOP_HPP_
template<typename T>
class IsClassT {
public:
enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};
enum { No = !Yes};
//int getInt(){return a;};

private:
typedef char One;
typedef struct { char a[2];} Two;
template<typename Cstatic One test(int C::*);
template<typename Cstatic Two test();
static const int a = 10;
};

Any ideas why I get this error?
IsClassT<T>::test is a dependent name, so you'll have to give the compiler a
hint so that it knows it's a template (instead of just testing whether
IsClassT<T>::test is smaller than T, which is an error as T is a type, not
an expression). Try this:

enum { Yes = sizeof(IsClassT<T>::template test<T>(0)) == 1};

- Sylvester Hesp
May 7 '07 #2
* desktop:
When I try to compile this template I get an error in the line:

"enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};"

saying:

blop.hpp:8: error: expected primary-expression before ‘>’ token
#ifndef BLOP_HPP_
#define BLOP_HPP_
template<typename T>
class IsClassT {
public:
enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};
enum { No = !Yes};
//int getInt(){return a;};

private:
typedef char One;
typedef struct { char a[2];} Two;
template<typename Cstatic One test(int C::*);
template<typename Cstatic Two test();
static const int a = 10;
};

Any ideas why I get this error?
One reason is that it's not known at that point that "test" is a
template. You could fix that by inserting the word "template", but
there are other problems. Try

template< typename T >
class IsClassT
{
private:
typedef char One;
typedef struct { char a[2];} Two;
template<typename Cstatic One test(int C::*);
template<typename Cstatic Two test(...);
public:
enum { yes = sizeof(test<T>(0)) == 1};
enum { no = !yes};
};

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 7 '07 #3
Alf P. Steinbach wrote:
* desktop:
>When I try to compile this template I get an error in the line:

"enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};"

saying:

blop.hpp:8: error: expected primary-expression before ‘>’ token
#ifndef BLOP_HPP_
#define BLOP_HPP_
template<typename T>
class IsClassT {
public:
enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};
enum { No = !Yes};
//int getInt(){return a;};
private:
typedef char One;
typedef struct { char a[2];} Two;
template<typename Cstatic One test(int C::*);
template<typename Cstatic Two test();
static const int a = 10;
};

Any ideas why I get this error?

One reason is that it's not known at that point that "test" is a
template. You could fix that by inserting the word "template", but
there are other problems. Try

template< typename T >
class IsClassT
{
private:
typedef char One;
typedef struct { char a[2];} Two;
template<typename Cstatic One test(int C::*);
template<typename Cstatic Two test(...);
public:
enum { yes = sizeof(test<T>(0)) == 1};
enum { no = !yes};
};
You prefer to change:

enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};

to:

enum { yes = sizeof(test<T>(0)) == 1};

but what if 'test' was a previous declared function outside IsClassT,
how would the compiler know which one to choose?

Besides from that I don't understand why it is illegal to access a
member in a class like:

IsClassT<T>::test<T>(0)

since that is how it is normally done (by using the qualify operator)
May 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
7
by: Andy Fish | last post by:
Hi, I'm stuck with an XSL problem - can anyone give me any hints? I have some XML with nested formatting tags like this: <text> this is plain <bold> this is bold
5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
2
by: littlefitzer | last post by:
Hi, I have come across a tricky little problem, I hope maybe one of you can help. The problem I am having is that I need to parse two seperate values from an XML document using XSL. The two...
4
by: C. Carbonera | last post by:
/* Hi, I have a problem with explicit instantiation of templates in Visual C++ 6.0. I have provided the source below. I have an example of a function template that produces incorrect output in...
7
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
7
by: StephQ | last post by:
First of all: distinction of keywords typename and class in template arguments. Accoarding to a post in a well known moderated group: "There are three possibilities for template arguments: 1)...
6
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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...
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
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,...
0
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...

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.