473,509 Members | 10,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New Managed class syntax

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
2 1881
> 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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3634
by: Scott Chang | last post by:
Hi all, I tried to use Managed C++ coding of VC++.NET (2002)and OpenGL version 1.2 to draw a hexagon shape of benzene. My OpenGLdrawBenzene.cpp is the following: // This is the main project file...
10
1615
by: Edward Diener | last post by:
The documentation states the names of the various managed operators but does not give the signature for them. Is there some documentation which I have missed that gives the correct signature ? In...
2
2303
by: Martin Zenkel | last post by:
Dear VS Team, using the Beta 2 of VS 2005 I've encontered the following problem. Let's assume threre are three Dll's, one unmanaged and two managed. In the unmanaged we put a simple unmanged...
3
1931
by: Tommy Svensson \(InfoGrafix\) | last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C# application. Now, the only way, as I've understood it, is to go the Managed Extensions for C++ way. This means I have to...
1
2539
by: Ghost | last post by:
Hi all, I wrote a program in C# and now I have to "translate" it i visual C++ (MFC) using .NET, but I had a little problem: *ERRORS* error C3181: 'CTestDlg' : invalid operand for __typeof,...
3
2756
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
2
5765
by: andy6 via DotNetMonster.com | last post by:
I took a c++ 6.0 project and converted it to c++ .net 2005 project. I want to make a web service out of it. One of the new files I created was a cpp where I have the webmethod pointing to a...
12
12501
by: DaTurk | last post by:
Hi, I have a rather interesting problem. I have a unmanged c++ class which needs to communicate information to managed c++ via callbacks, with a layer of c# on top of the managed c++ ultimatley...
2
2287
by: kelvin.koogan | last post by:
Our company has a mix of users with VS2003 & VS2005. I'm am having difficulty working out how components written with these 2 tools can be written together. I want to be able to a) incorporate a...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.