Hi
I have this code:
[begin main.cpp]
template<typena me ClassType>
struct S
{
template<typena me FunctionType> void member() {};
};
template<typena me Type>
void g()
{
S<Type> s;
/*line 11*/ s.member<Type>( );
}
void h()
{
S<int> s;
s.member<int>() ;
}
int main(int, char**)
{
g<int>();
h();
return 0;
}
[end main.cpp]
I compile it with g++ (GCC) 3.4.2 (mingw-special) and get this compiler
error:
.../main.cpp: In function `void g()':
.../main.cpp:11: error: expected primary-expression before '>' token
.../main.cpp:11: error: expected primary-expression before ')' token
I do not understand what is wrong with the expression in Line 11 and
where the difference between the calls in g and h is.
Can anyone explain this?
TIA
Gabriel 13 10686
Gabriel, I took your code and compiled it with MSVC 7.1 , which
increases conformance with C++ standard. It compiled and ran OK. I know
MSVC7.1 and g++ 3.4.2 are different but don't both compilers try to
conform with C++ standard? Thank you
Frank Chang wrote: Gabriel, I took your code and compiled it with MSVC 7.1 , which increases conformance with C++ standard. It compiled and ran OK. I know MSVC7.1 and g++ 3.4.2 are different but don't both compilers try to conform with C++ standard? Thank you
Thank you, Frank
Yes, I think that they both try to conform to the standard. And I think
g++ 3.4 (or later) is very close to the standard. As far as I understand
the language, my code should be correct, but I am not sure if the g++
should translate it or if the MSVC makes a mistake by translating it.
If it's a problem with the g++, does anyone know a workaround?
Some additional information:
I just ran it under the IAR Embedded Workbench IDE with the MSP430 IAR
C/C++ Compiler, and it tells me
Error[Pe254]: type name is not allowed H:\Projects\Tes t (IAR Embedded
Workbench IDE)\main.cpp 11
Error[Pe029]: expected an expression H:\Projects\Tes t (IAR Embedded
Workbench IDE)\main.cpp 11
Gabriel
Gabriel wrote: If it's a problem with the g++, does anyone know a workaround?
FWIW, The code that you posted doesn't compile with g++ 3.3.4 as well.
Anyway, as a work around you can add a dummy parameter to the
templated member function.
template<typena me ClassType>
struct S
{
template<typena me FunctionType> void member(Function Type* t =0) {};
};
template<typena me Type>
void g()
{
S<Type> s;
s.member( static_cast<Typ e*>(0) );
}
Rgds,
anna
john.constantin e wrote: Hi I have this code:
[begin main.cpp] template<typena me ClassType> struct S { template<typena me FunctionType> void member() {};
Drop the trailing semicolon: while it is not a severe violation,
it is entirely superfluous and a bad habit.
};
template<typena me Type> void g() { S<Type> s; /*line 11*/ s.member<Type>( );
Needs to be
s.template member<Type>();
to be standard C++. MS compiler hasn't got there yet.
}
void h() { S<int> s; s.member<int>() ; }
int main(int, char**) { g<int>(); h(); return 0; } [end main.cpp]
I compile it with g++ (GCC) 3.4.2 (mingw-special) and get this compiler error: ../main.cpp: In function `void g()': ../main.cpp:11: error: expected primary-expression before '>' token ../main.cpp:11: error: expected primary-expression before ')' token
I do not understand what is wrong with the expression in Line 11 and where the difference between the calls in g and h is.
Can anyone explain this?
A template member of a template needs to be specified as such to help
the compiler resolve the name. I don't remember the exact paragraph
of the Standard, but you could search the archives on Google, it has
come up more than once in this newsgroup.
V an************* ***@gmail.com wrote: Gabriel wrote:
If it's a problem with the g++, does anyone know a workaround?
FWIW, The code that you posted doesn't compile with g++ 3.3.4 as well. Anyway, as a work around you can add a dummy parameter to the templated member function.
template<typena me ClassType> struct S { template<typena me FunctionType> void member(Function Type* t =0) {}; };
template<typena me Type> void g() { S<Type> s; s.member( static_cast<Typ e*>(0) ); }
Rgds, anna
That's a nifty solution! I think that will help me out for now...
Thanx anna!
Gabriel
Victor Bazarov wrote: john.constantin e wrote:
Hi I have this code:
[begin main.cpp] template<typena me ClassType> struct S { template<typena me FunctionType> void member() {};
Drop the trailing semicolon: while it is not a severe violation, it is entirely superfluous and a bad habit.
};
template<typena me Type> void g() { S<Type> s; /*line 11*/ s.member<Type>( );
Needs to be s.template member<Type>();
to be standard C++. MS compiler hasn't got there yet.
}
void h() { S<int> s; s.member<int>() ; }
int main(int, char**) { g<int>(); h(); return 0; } [end main.cpp]
I compile it with g++ (GCC) 3.4.2 (mingw-special) and get this compiler error: ../main.cpp: In function `void g()': ../main.cpp:11: error: expected primary-expression before '>' token ../main.cpp:11: error: expected primary-expression before ')' token
I do not understand what is wrong with the expression in Line 11 and where the difference between the calls in g and h is.
Can anyone explain this?
A template member of a template needs to be specified as such to help the compiler resolve the name. I don't remember the exact paragraph of the Standard, but you could search the archives on Google, it has come up more than once in this newsgroup.
V
Thank you, Victor.
I have never seen this before. Even in the Stroustrup I could not find it.
What I still not understand is why the call in h is valid and the call
in (the template function) g is not valid.
Gabriel
Gabriel wrote: Victor Bazarov wrote:
john.constantin e wrote:
Hi I have this code:
[begin main.cpp] template<typena me ClassType> struct S { template<typena me FunctionType> void member() {}; Drop the trailing semicolon: while it is not a severe violation, it is entirely superfluous and a bad habit.
};
template<typena me Type> void g() { S<Type> s; /*line 11*/ s.member<Type>( ); Needs to be s.template member<Type>();
to be standard C++. MS compiler hasn't got there yet.
}
void h() { S<int> s; s.member<int>() ; }
int main(int, char**) { g<int>(); h(); return 0; } [end main.cpp]
I compile it with g++ (GCC) 3.4.2 (mingw-special) and get this compiler error: ../main.cpp: In function `void g()': ../main.cpp:11: error: expected primary-expression before '>' token ../main.cpp:11: error: expected primary-expression before ')' token
I do not understand what is wrong with the expression in Line 11 and where the difference between the calls in g and h is.
Can anyone explain this? A template member of a template needs to be specified as such to help the compiler resolve the name. I don't remember the exact paragraph of the Standard, but you could search the archives on Google, it has come up more than once in this newsgroup.
V
Thank you, Victor. I have never seen this before. Even in the Stroustrup I could not find it.
What I still not understand is why the call in h is valid and the call in (the template function) g is not valid.
'h' is not a template itself. 'g' is a template. The names are resolved
differently inside those scopes. Get a copy of "C++ Templates" by David
Vandevoorde and Nicolai Josuttis. It's an extremely helpful book. It
doesn't just tell you how, it explains why certain things are done the way
they are done.
V
Victor Bazarov wrote: Needs to be s.template member<Type>();
to be standard C++. MS compiler hasn't got there yet.
I haven't yet written (or maintained) template heavy C++ code.
So, this is new for me (obvious, if you had a look at my
previous post, which the OP was kind enough to call nifty.)
My question is if the original code was incorrect, and MS
compiler compiled it successfully, what does it mean? Will
the MS compiler generate wrong object code for correct
(standard compliant) C++ code, in some very rare cases?
(Probably template heavy stuff.)
Any thoughts on that?
Rgds,
anna This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tyousaf |
last post by:
Hi
i am new to mysql and mysql++, i have installed mysql server, it is
running fine. i also installed "mysql++-1.7.9gcc3.2-2.i386.rpm" (i
have gcc 3.3) , first of all as the readme file says to do automake,
if i do that in the proper director it says "automake: 'configure.ac'
or 'configure.in' is required" i dont know where to bring those files.
secondly if i only compile simple1.cc using gcc proving all the link
flags to libraries and...
|
by: ogtindeed |
last post by:
Hi all,
I need some help. I am trying to instantiate a Template and call a
member function, but have not been able -
Now this is what I am trying to do:
foo.h
=========
|
by: Martin MacRobert |
last post by:
Hi Gang,
The following code does not compile, but I can't figure out why. The
compiler complains that the CuriouslyDerivedType (CRDerived) does not
publish the "value_type", yet in fact the class CRDerived does.
Is there any way of making the code work? I would like functions to
accept a CRBase template, and the CRBase must be able to deduce the
"value_type" of the function that it is "curiously calling".
Thanks.
|
by: Robbie Hatley |
last post by:
I've got a function that I use a lot when making utility programs
that need to do the same thing to every directory in a tree.
Its prototype is:
unsigned long int CursDirs (void Func(void));
This just applies the fuction Func to every subdirectory of the
current directory. It works fine when I pass it pointers to regular
void-void functions.
|
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
| |
by: Nafai |
last post by:
Hello. I'll try to explain my problem with an example:
I have the following classes:
class A {
public:
string name;
....
};
|
by: kamaraj80 |
last post by:
Hi
I am using the std:: map as following.
typedef struct _SeatRowCols
{
long nSeatRow;
unsigned char ucSeatLetter;
}SeatRowCols;
typedef struct _NetData
|
by: StephQ |
last post by:
In utility.hpp I have:
namespace utility
{
template <class T, double (T::*F)(double) const>
class Display
{
private:
static double resolution;
|
by: Gaijinco |
last post by:
I'm trying to do a template class Node.
My node.hpp is:
#ifndef _NODE_HPP_
#define _NODE_HPP_
namespace com { namespace mnya { namespace carlos {
template <typename T>
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |