views:

381

answers:

4

I have downloaded the Phoenix SDK June 2008 (Tools for compilers) and when I'm reading the code of the Hello sample, I really feel lost.

public
ref class Hello
{
//--------------------------------------------------------------------------
//
// Description:
//
//    Class Variables.
//
// Remarks:
//
//    A normal compiler would have more flexible means for holding
//    on to all this information, but in our case it's simplest (if
//    somewhat inelegant) if we just keep references to all the
//    structures we'll need to access as classstatic variables.
//
//--------------------------------------------------------------------------

static Phx::ModuleUnit                 ^ module;
static Phx::Targets::Runtimes::Runtime ^ runtime;
static Phx::Targets::Architectures::Architecture       ^ architecture;
static Phx::Lifetime                   ^ lifetime;
static Phx::Types::Table               ^ typeTable;
static Phx::Symbols::Table                ^ symbolTable;
static Phx::Phases::PhaseConfiguration        ^ phaseConfiguration;

2 Questions : What's that ref keyword? What is that sign ^ ? What is it doing

protected:

  virtual void
  Execute
  (
     Phx::Unit ^ unit
  ) override;

};

override is a C++ keyword too? It's colored as such in my Visual Studio. I really want to play with this framework, but this advanced C++ is really an obstacle right now. Thank you.

+12  A: 

It's not standard C++, it's C++/CLI.

Klaim
I guess this is why Sun sue Microsoft years ago, to prevent this kind of "enhancements"
OscarRyz
roughly speaking yeah
1800 INFORMATION
They're not enhancements. This is a separate language. It is not C++. Microsoft doesn't claim that it is C++. C++/CLI is technically a completely different beast.
jalf
C++/CLI just has that annoying similarity in naming, like Java and JavaScript.
Greg Hewgill
And the extension is .cpp, I was totally expecting to see C++ code:( Thanks for all the answers guys!
toto
+5  A: 

It's a Microsoft extension for use with .NET. The caret indicates a handle to an object stored on the managed heap. See Bran Bray's blog for a nice description.

Mr Fooz
+5  A: 

It is C++/CLI - code that is written to be run as managed code under the .Net framework, not regular C++ code.

  • ref - this class is a reference type, it is allocated in the managed heap and will be garbage collected
  • ^ - this variable is a handle to a managed instance
  • override - this method overrides the base class implementation
1800 INFORMATION
+3  A: 

That is not part of standard C++. It's C++/CLI, which is a Microsoft language specification designed to replace Managed C++:

C++/CLI (Common Language Infrastructure) is Microsoft's language specification intended to supersede Managed Extensions for C++. Completely revised to simplify the older Managed C++ syntax (which is now deprecated), it provides much more clarity and code readability than Managed C++. C++/CLI is standardized by Ecma as ECMA-372. It is currently only available in Visual Studio 2005 and 2008 (also included in the Express Editions).

The caret symbol is the C++/CLI equivalent of a pointer, as described in Rob Walker's answer to this question:

...the caret is the managed equivalent of a * (pointer) which in C++/CLI terminology is called a 'handle' to a 'reference type' (since you can still have unmanaged pointers). See this overview from Microsoft.

The usage of "ref class X" instead of the familiar "class X" is discussed in this blog post.

William Brendel