473,804 Members | 2,107 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("Poo h"); svec->push_back("Pig let");
svec->push_back("Eey ore"); svec->push_back("Rab bit");

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

Console::WriteL ine( "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("Poo h").
Actually, if they write it like that (svec->push_back("Poo h")) 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(*labe l) ?or StringXml.Conca t(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 1894
> 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("Poo h"); svec->push_back("Pig let");
svec->push_back("Eey ore"); svec->push_back("Rab bit");

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

Console::WriteL ine( "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("Poo h").
Actually, if they write it like that (svec->push_back("Poo h")) 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(*labe l) ?or StringXml.Conca t(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("Poo h"); svec->push_back("Pig let");
svec->push_back("Eey ore"); svec->push_back("Rab bit");

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

Console::WriteL ine( "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("Poo h"). 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(*labe l) ?or StringXml.Conca t(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
3647
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 for VC++ application project // generated using an Application Wizard. #include "stdafx.h" #include <stdlib.h>
10
1651
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 particular I want to implement the op_Assign (=) operator for a __value struct.
2
2329
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 struct "A" which is exported in the usual way. The first managed assembly defines a managed class "B" using the unmanaged class "A" defined in the unmanaged Dll. This class "B" has got a public
3
1958
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 write a wrapper between unmanaged API and my managed app. Now on to the question: If there's an unmanaged API class called X with a defined method
1
2553
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, expected fully defined managed type error C3363: 'void CTestDlg::BtnAboutClick(System::Object __g *,System::EventArgs __gc *)' : cannot create a delegate handler fo 'System::EventHandler' from a non-member function or a member of a
3
2784
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 question.
2
5789
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 function in the previously 6.0 code and I get the error noted below. What I don't understand is since I created this cpp as a new file in .net and inherited from a .net base class then why would I get this error? Both the class and base class to me...
12
12559
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 retreiving the data. Presently all of the c++ code is still in .NET 1.1, so we're using a _nogc bridge class wrapped in a _gc c++ class in order to facilitate this interop. But we've converted everything not c++ to .NET 2.0 and would love to
2
2317
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 C++/CLI DLL written in VS2005 into a managed extensions app written with VS2003 and b) use a managed extensions DLL written with VS2003 in a C++/CLI app written in VS2005. How can I do this? Immediate problems I found:
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
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 we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.