473,664 Members | 2,728 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::MyCl ass>();
}
////////////////////////////// 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 1635
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
5118
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 the days before PHP got object-oriented features. For instance we currently have:
1
2225
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
1991
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
7501
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 namespace definition with class definitions. The book says "C++ has a global anonymous namespace that is similar to Java's global anonymous package. All declarations not explicitly placed in named
59
3906
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 candidate for Python 3000 yet? Chris
6
5405
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, vectors, operator overloading and what not.. And i was wondering if there is a way to override the global dereference operator, so to be able to check the address that one tries to dereference. This gives the ability to throw an exception when...
3
2276
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 window) ++num;
11
22349
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 type specified. This is much similar like a macro expansion in C. can anyone please explain advantages of one over the other ? Thanks in advance -
5
11811
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 $MYVAR, $a; ?>
1
29345
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 called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
0
8437
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
8861
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, 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...
1
8549
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,...
0
7375
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
6187
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
5660
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
4185
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
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.