473,395 Members | 1,666 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,395 software developers and data experts.

Why this does not compile?

Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".

cheers,
Marcin

Nov 4 '05 #1
3 1460
Marcin Kalicinski wrote:
Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".
...


Template members of dependent types have to be referred to with the explicit use
of keyword 'template'

template<class T>
double g()
{
T t;
return t.template f<double>(3);
}

--
Best regards,
Andrey Tarasevich
Nov 4 '05 #2
> Template members of dependent types have to be referred to with the
explicit use
of keyword 'template'

template<class T>
double g()
{
T t;
return t.template f<double>(3);
}

Thanks, that was quick!

Best regards,
Marcin
Nov 4 '05 #3
In article <bc*****************@newsfe2-win.ntli.net>,
Marcin Kalicinski <ka****@poczta.onet.pl> wrote:
Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".


Check out http://www.comeaucomputing.com/techt...templateprefix
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 5 '05 #4

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

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
8
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
4
by: Alex Vinokur | last post by:
Compiler GNU gpp.exe (GCC) 3.4.1 Foo(300) = Foo(500); // Foo(300) is const. Why does a compiler compile that? ------ foo.cpp ------ struct Foo { explicit Foo(int) {}
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: ziman137 | last post by:
Hi all, The results from following codes got me a bit confused. #include <stdio.h> #include <iostream> using namespace std; struct A {
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
11
by: MonkeeSage | last post by:
A quick question about how python parses a file into compiled bytecode. Does it parse the whole file into AST first and then compile the AST, or does it build and compile the AST on the fly as it...
5
by: Jeff | last post by:
hi asp.net 2.0 I get this compile error: 'Image' does not contain a definition for 'ImageUrl' Image image = (Image)e.Item.FindControl("img"); image.ImageUrl = "~/image.png";
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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...

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.