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

[VS2005] c++ "scope operator"

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 ==========
Nov 17 '05 #1
3 3418
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
Nov 17 '05 #2
Jacobo Rodriguez Villar wrote:
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.
Nov 17 '05 #3
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.

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #4

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

Similar topics

34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
5
by: William | last post by:
In Peer.h, I have: class Peer { // ... }; In Overseer.h, I have: #include "Peer.h" #include <vector>
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
1
by: G Fernandes | last post by:
Scope is a property of identifiers and defines where they are visible in a source file. Why then do most writings on C also use the word "scope" to refer to a property of different points of a...
39
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the...
9
by: Emanuele Aina | last post by:
I have some code which does a lot of "in" on lists containing objects with no __eq__ defined. It all goes fast until I add the __lt__() method: then I have a slowdown comparable to the one I get...
2
by: John Goche | last post by:
Hello, Could anyone please provide with some information on the C++ overloaded cast operator and in which circumstances this might be useful? I have consulted several references but found no...
2
by: dhtmlkitchen | last post by:
I'm trying to learn something about JScript engine. I have the following example: <script>(function() { poop = "brown"; myFunction = function myFunction() {}
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.