Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2004

Tip: Looking for answers? Try searching our database.

[VS2005] c++ "scope operator"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
marco_segurini - 02 Nov 2004 09:53 GMT
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 Rodriguez Villar - 02 Nov 2004 10:40 GMT
Because .PI is a 'structure' member and Cos is static function member

> Hi,
>
[quoted text clipped - 46 lines]
> scope - 1 error(s), 2 warning(s)
> ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Signature

Jacobo Rodríguez Villar

TyphoonLabs Lead Programmer

http://www.typhoonlabs.com

Marco Segurini - 02 Nov 2004 11:48 GMT
> 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.
Tomas Restrepo \(MVP\) - 03 Nov 2004 00:20 GMT
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.

Signature

Tomas Restrepo
tomasr@mvps.org


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.