By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

New Managed class syntax

P: n/a
Hi,

First of all, i want to use the new managed class syntax and STL.NET
under Microsoft Visual (C++) Studio 2005 Beta.
I read in a Microsoft
article(http://msdn.microsoft.com/VISUALC/de...-netprimer.asp)
that i am suposed to include :
#include <cli/vector>
#include <algorithm>

in order to use properly STL.NET. However, everytime i include
#include <cli/vector> the compilator says : fatal error C1083
cannot open include file 'cli/vector' no such file or directory.So, i
can't use vectors, what i don't understand.

Secondly, i don't really get the purpose of the new managed class
syntax purpose. Before it was _gc class Myclass and now it's ref
class Myclass . Before we could write String * ptr and now it's
String ^ ptr.

Recently,i read an article from microsoft in their web site concerning
the new managed class syntax :
this is what i read :
"C++/CLI introduces a new category of type, the handle, which is used
to signify the use of automatic garbage collection. Handles borrow
the syntax of pointers, but use the carat (^) in place of the
asterisk (*). The keyword gcnew is used to create these garbage
collected objects, and returns a handle:

MyRefClass ^ c = gcnew MyRefClass();
"

they talk about handle.

in another article from Microsoft on the same topic. here is what i
read:
(it was an example about how to use the STL.NET new syntax)
"vector<String^> ^svec = gcnew vector<String^>;

svec->push_back("Pooh"); svec->push_back("Piglet");
svec->push_back("Eeyore"); svec->push_back("Rabbit");

// generic algorithm: sort
sort( svec->begin(), svec->end() );

Console::WriteLine( "Collection holds {0} elements: ",
svec->size() );"

My question is : if svec is a handle why don't we write:
svec.push_back("Pooh") instead of : svec->push_back("Pooh").
Actually, if they write it like that (svec->push_back("Pooh")) svec
is a pointer and not a handle. So, another question would be what's
the use for them to introduce the ^ sign if it works exactly the same
as the * sign?

Actually, i a m confused :
In my program, i cannot declare String label but String ^label(it's
mandatory). I have another String ^StringXML;
when i want to append them should i write stringXml->Concat(label)
?
or StringXml->Concat(*label) ?or StringXml.Concat(label) or
whatever...

There must be an answer.

I thank u in advance

Sincerely,

bor_kev
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> First of all, i want to use the new managed class syntax and STL.NET
under Microsoft Visual (C++) Studio 2005 Beta.
I read in a Microsoft
article(http://msdn.microsoft.com/VISUALC/de...ibrary/en-us/d
nvs05/html/stl-netprimer.asp) that i am suposed to include :
#include <cli/vector>
#include <algorithm>

in order to use properly STL.NET. However, everytime i include
#include <cli/vector> the compilator says : fatal error C1083
cannot open include file 'cli/vector' no such file or directory.So, i
can't use vectors, what i don't understand.
STL.NET has not been included yet in any build of VS 2005 so far. You'll
need to wait until beta2, I believe...
Secondly, i don't really get the purpose of the new managed class
syntax purpose. Before it was _gc class Myclass and now it's ref
class Myclass . Before we could write String * ptr and now it's
String ^ ptr.

Recently,i read an article from microsoft in their web site concerning
the new managed class syntax :
this is what i read :
"C++/CLI introduces a new category of type, the handle, which is used
to signify the use of automatic garbage collection. Handles borrow
the syntax of pointers, but use the carat (^) in place of the
asterisk (*). The keyword gcnew is used to create these garbage
collected objects, and returns a handle:

MyRefClass ^ c = gcnew MyRefClass();
"

they talk about handle.

in another article from Microsoft on the same topic. here is what i
read:
(it was an example about how to use the STL.NET new syntax)
"vector<String^> ^svec = gcnew vector<String^>;

svec->push_back("Pooh"); svec->push_back("Piglet");
svec->push_back("Eeyore"); svec->push_back("Rabbit");

// generic algorithm: sort
sort( svec->begin(), svec->end() );

Console::WriteLine( "Collection holds {0} elements: ",
svec->size() );"

My question is : if svec is a handle why don't we write:
svec.push_back("Pooh") instead of : svec->push_back("Pooh").
Actually, if they write it like that (svec->push_back("Pooh")) svec
is a pointer and not a handle.
Nope, because the syntax used to access members on a handle and a pointer is
still the same ->. The compiler sure knows the real type and can generate
the correct code.
So, another question would be what's
the use for them to introduce the ^ sign if it works exactly the same
as the * sign?
It does't work in the same way. You should really look at the C++/CLI
specification, it is covered much in detail there.

Actually, i a m confused :
In my program, i cannot declare String label but String ^label(it's
mandatory). I have another String ^StringXML;
when i want to append them should i write stringXml->Concat(label)
?
or StringXml->Concat(*label) ?or StringXml.Concat(label) or
whatever...


The first one, of course.

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

P: n/a

bor_kev wrote:
Hi,

First of all, i want to use the new managed class syntax and STL.NET
under Microsoft Visual (C++) Studio 2005 Beta.
I read in a Microsoft
article(http://msdn.microsoft.com/VISUALC/de...-netprimer.asp) that i am suposed to include :
#include <cli/vector>
#include <algorithm>

in order to use properly STL.NET. However, everytime i include
#include <cli/vector> the compilator says : fatal error C1083
cannot open include file 'cli/vector' no such file or directory.So, i
can't use vectors, what i don't understand. STL.NET has not been released yet, even as Beta.
Secondly, i don't really get the purpose of the new managed class
syntax purpose. Before it was _gc class Myclass and now it's ref
class Myclass . Before we could write String * ptr and now it's
String ^ ptr.

Recently,i read an article from microsoft in their web site concerning the new managed class syntax :
this is what i read :
"C++/CLI introduces a new category of type, the handle, which is used
to signify the use of automatic garbage collection. Handles borrow
the syntax of pointers, but use the carat (^) in place of the
asterisk (*). The keyword gcnew is used to create these garbage
collected objects, and returns a handle:

MyRefClass ^ c = gcnew MyRefClass();
"

they talk about handle. Yes, the handle is what was called on VC2003 "managed pointer". The new
syntax has been introduced because of confusion between managed
pointers and non-managed pointers (the VC2003 syntac was really
awfull).
in another article from Microsoft on the same topic. here is what i
read:
(it was an example about how to use the STL.NET new syntax)
"vector<String^> ^svec = gcnew vector<String^>;

svec->push_back("Pooh"); svec->push_back("Piglet");
svec->push_back("Eeyore"); svec->push_back("Rabbit");

// generic algorithm: sort
sort( svec->begin(), svec->end() );

Console::WriteLine( "Collection holds {0} elements: ",
svec->size() );"

My question is : if svec is a handle why don't we write:
svec.push_back("Pooh") instead of : svec->push_back("Pooh"). Because MS decided that the indirection operator for handles was "->",
not ".". I remember having read somewhere that there has been some
discussion inside MS to know which syntax was best. I believe they made
the right choice, since the "->" syntax reminds us that we are not
manipulating directly the object, but an indirect representation of it
(same thing with pointers and handles).
So, another question would be what's
the use for them to introduce the ^ sign if it works exactly the same
as the * sign? As I said, to disambiguate between managed and unmanaged pointers. You
cannot do the same thinghs with the 2. For example, you cannot do
handle arithmetic as pointer arithmetic, and the same goes for casting.
On the other hand, the object "pointed to" by a handle can be moved in
memory by the GC, while the pointer has no such capacity.
Actually, i a m confused :
In my program, i cannot declare String label but String ^label(it's
mandatory). Yes : a managed type must be allocated on the managed heap, it cannot
be allocated on the stack. It therefore can be manipulated only through
a handle, and must be "gcnewed".
I have another String ^StringXML;
when i want to append them should i write stringXml->Concat(label)
?
or StringXml->Concat(*label) ?or StringXml.Concat(label) or
whatever...


None of the above, since all overloads of String::Concat are static.

Arnaud
MVP - VC

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.