[VS2005] c++ "scope operator"

M

marco_segurini

Hi,

I am using VS 2005.

If I compile the following code only line 6 returns me an error while
line 9 returns a warning. If I comment the line 6 and debug the
program the assignments of lines {9, 11} work fine.

Why the '.' "scope operator" is accepted in line 9 and not in line 6?

thanks.
Marco.

//-----------
using namespace System;

int main()
{
double d;
d = Math.Cos(1.0); // line 6
d = Math::Cos(1.0);

d = Math.PI; // line 9
d = 0;
d = Math::pI; // line 11
}

------ Rebuild All started: Project: scope, Configuration: Debug Win32
------
Deleting intermediate and output files for project 'scope',
configuration 'Debug|Win32'
Compiling...
stdafx.cpp
Compiling...
scope.cpp
scope.cpp(6) : warning C4832: token '.' is illegal after UDT
'System::Math'
scope.cpp : see declaration of 'System::Math'
scope.cpp(6) : error C2275: 'System::Math' : illegal use of this type
as an expression
scope.cpp : see declaration of 'System::Math'
scope.cpp(9) : warning C4832: token '.' is illegal after UDT
'System::Math'
scope.cpp : see declaration of 'System::Math'
AssemblyInfo.cpp
Generating Code...
Build log was saved at "file://e:\Project C++ NET
2005\Prove\scope\scope\Debug\BuildLog.htm"
scope - 1 error(s), 2 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
 
J

Jacobo Rodriguez Villar

Because .PI is a 'structure' member and Cos is static function member
Hi,

I am using VS 2005.

If I compile the following code only line 6 returns me an error while
line 9 returns a warning. If I comment the line 6 and debug the
program the assignments of lines {9, 11} work fine.

Why the '.' "scope operator" is accepted in line 9 and not in line 6?

thanks.
Marco.

//-----------
using namespace System;

int main()
{
double d;
d = Math.Cos(1.0); // line 6
d = Math::Cos(1.0);

d = Math.PI; // line 9
d = 0;
d = Math::pI; // line 11
}

------ Rebuild All started: Project: scope, Configuration: Debug Win32
------
Deleting intermediate and output files for project 'scope',
configuration 'Debug|Win32'
Compiling...
stdafx.cpp
Compiling...
scope.cpp
scope.cpp(6) : warning C4832: token '.' is illegal after UDT
'System::Math'
scope.cpp : see declaration of 'System::Math'
scope.cpp(6) : error C2275: 'System::Math' : illegal use of this type
as an expression
scope.cpp : see declaration of 'System::Math'
scope.cpp(9) : warning C4832: token '.' is illegal after UDT
'System::Math'
scope.cpp : see declaration of 'System::Math'
AssemblyInfo.cpp
Generating Code...
Build log was saved at "file://e:\Project C++ NET
2005\Prove\scope\scope\Debug\BuildLog.htm"
scope - 1 error(s), 2 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


--
Jacobo Rodríguez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com
 
M

Marco Segurini

Jacobo said:
Because .PI is a 'structure' member and Cos is static function member

Thanks Jacobo,

the Intellisense tells me that PI and Cos are both 'static members' of
the Math class. So like happens using a not managed c++ class only one
scope syntax has to be permitted :):).

Bye.
Marco.
 
T

Tomas Restrepo \(MVP\)

Marco,
Thanks Jacobo,

the Intellisense tells me that PI and Cos are both 'static members' of
the Math class.

They are.
So like happens using a not managed c++ class only one
scope syntax has to be permitted :):).

Well, as it should, since they are static (and there's no instance to call
it from). The code is incorrect in that it tried to use the '.' operator to
reference Math::pI.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top