Hi all. I'm doing some programming in Qt, but it uses Microsoft's compiler. Microsoft and Gnu seem to disagree on what's legal. Below is an example of the problem. Can anybody tell me what Microsoft is looking at? Is there some implied namespace or something?
The Gnu version (works) :
Rick@RicksLaptop /cygdrive/c/temp
$ g++ scope_operator.cpp
Rick@RicksLaptop /cygdrive/c/temp
$ cat scope_operator.cpp
// scope_operator.cpp : Defines the entry point for the console application.
//
// #include "stdafx.h"
int ::globalFunction(void) {
return 10;
}
class TestClass {
public:
friend int ::globalFunction(void);
};
int main(int argc, char* argv[])
{
return 0;
}
Rick@RicksLaptop /cygdrive/c/temp
$ g++ scope_operator.cpp
Rick@RicksLaptop /cygdrive/c/temp
$
The Microsoft version (fails) :
c:\Users\Rick\Documents\Visual Studio 2008\Projects\scope_operator\scope_operato
r>type scope_operator_usoft.cpp
// scope_operator.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int ::globalFunction(void) {
return 10;
}
class TestClass {
public:
friend int ::globalFunction(void);
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
c:\Users\Rick\Documents\Visual Studio 2008\Projects\scope_operator\scope_operato
r>cl scope_operator_usoft.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
scope_operator_usoft.cpp
scope_operator_usoft.cpp(7) : error C2039: 'globalFunction' : is not a member of
'`global namespace''
c:\Users\Rick\Documents\Visual Studio 2008\Projects\scope_operator\scope_operato
r>
If this is some syntax that is supposed to be legal in standard C++, could somone explain why? It seems weird to specify that you are in a scope that you are already in...
Well, this is a simplied version of something else. I was really trying to provide a friend operator<< for a class. I got all kinds of error messages, and this is my attempt to get it down to just one that happens with a small amount of code.
I'm hoping if I understand why Microsoft complains about this, I can transfer the information to the more complicated situation.
Well, I guess if Comeau says it isn't standard, it isn't standard.
Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 1: error: nonstandard qualified name in global scope
declaration
int ::globalFunction(void) {
^
1 error detected in the compilation of "ComeauTest.c".
In strict mode, with -tused, Compile failed
Hit the Back Button to review your code and compile options.
Compiled with C++0x extensions enabled.