473,506 Members | 17,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global templates and namespaces

Hello all,

I have a piece of code which compiles with gcc-3.4 but not with intel compiler 8.1. If I correct
the code for intel compiler, then gcc refuses to compile it. The code is following:

////////////////////////////////// test.cpp
template <typename T>
void func ()
{
static T instance;
}

namespace blah {

class MyClass {
friend void func<MyClass> ();

MyClass () {} // private
};

}
int main ()
{
func<blah::MyClass>();
}
////////////////////////////// end of test.cpp

Error is in the 'friend void func<MyClass> ();' line. When I compile this file with
intel compiler, it says

test.cpp(4): error #373: "blah::MyClass::MyClass()" is inaccessible
static T instance;
^
detected during instantiation of "void func<T>() [with T=blah::MyClass]"

To make the compiler happy I change MyClass to

class MyClass {
friend void ::func<MyClass> (); // note the :: before func

MyClass () {}
};

But when g++ says
test2.cpp:11: error: `void func()' should have been declared inside `::'.

What's correct? I tried Comeau compiler on comeaucomputing.com, it compiles both
versions. Is this just two different bugs of g++ and intel compiler?

Thank you,
Yevgen
Jul 22 '05 #1
3 1630
Yevgen Muntyan wrote:
...
What's correct? I tried Comeau compiler on comeaucomputing.com, it
compiles both
versions. Is this just two different bugs of g++ and intel compiler?


I think it's two different bugs and Comeau is right (again).
Jul 22 '05 #2
Gianni Mariani wrote:
Yevgen Muntyan wrote:
..
What's correct? I tried Comeau compiler on comeaucomputing.com, it
compiles both
versions. Is this just two different bugs of g++ and intel compiler?

I think it's two different bugs and Comeau is right (again).


I think the GCC bug is:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8355
Jul 22 '05 #3
Gianni Mariani wrote:
....
I think the GCC bug is:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8355


Seems yes. Well, it's not that bad - at least I'm not going to use Visual Studio...

Regards,
Yevgen
Jul 22 '05 #4

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

Similar topics

88
5053
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
1
2217
by: Andr? Roberge | last post by:
I have the following two files: #--testexec.py-- def exec_code(co): try: exec co except: print "error" #-- test.py--
12
1980
by: Santiago de Compostela | last post by:
Hi The following program doesn't compile on MS VC++ or Bloodshed Dev-C++ #include <iostream> int strlen(const char *in) {
2
7497
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
59
3874
by: seberino | last post by:
I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a...
6
5386
by: TuxC0d3 | last post by:
Hi! I'm diving into the some more ++ specific aspects of c++ (and finally accepting that c++ is more than "a plus added to c" :), so that means using namespaces, templates, std::strings, lists,...
3
2263
by: sundew | last post by:
so here is the test case: <head> <script type='text/javascript'> // this function simply returns the number of enumerable namespaces(objects) function numNSpaces(){ var num = 0; for(var i in...
11
22322
by: San | last post by:
hi there, I am new to c++ and tryig to learn the basics of the c++ concepts. While I was reading the templates, I realize that the templates are a syntax that the compilar expands pased upon the...
5
11800
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
29312
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
7105
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
7308
Oralloy
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,...
0
7479
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...
0
5617
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,...
1
5037
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...
0
4702
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...
0
3188
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...

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.