473,772 Members | 3,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<typena me 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<typena me Cstatic One test(int C::*);
template<typena me Cstatic Two test();
static const int a = 10;
};

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

"desktop" <ff*@sss.comwro te 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<typena me 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<typena me Cstatic One test(int C::*);
template<typena me Cstatic Two test();
static const int a = 10;
};

Any ideas why I get this error?
IsClassT<T>::te st 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>::te st 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<typena me 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<typena me Cstatic One test(int C::*);
template<typena me 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<typena me Cstatic One test(int C::*);
template<typena me 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<typen ame 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<typena me Cstatic One test(int C::*);
template<typena me 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<typena me Cstatic One test(int C::*);
template<typena me 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>::te st<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
3406
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 happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
7
3126
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
7420
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 collection that I need. To begin, I am using xsltproc that conmes with Cygwin as my processor. I have no particular affinity to this processor except that it is open source and standards compliant. I don't like M$, but if using a M$ processing...
2
2219
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 elements however are identical in their names and XPath appearing as below in the XML (I have left out XPath as they are the same): <esb:AcctTypeCode>43</esb:AcctTypeCode> <esb:AcctTypeCode>21</esb:AcctTypeCode>
4
2608
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 the code below. The function template < typename T >
7
2004
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
2131
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
13278
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 <hash_map>//from Standard template library //and some other headers
7
2127
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) type as in "template <typename T>" or "template <class T>" 2) non-type as in "template <int N>" 3) class template as in "template <template<typenameclass C>" "
6
4552
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 the game is to find a zero of this function f (the point at which f crosses the x-axis). This zero-of-f which solves our problem is the double which NR returns. It remains to explain what the "double x" represents. This is the...
0
9620
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8934
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6715
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.