passing a stream as parameter
I setup the following test
void test(System::IO::Stream pStream)
{
}
Not much here, I just want to pass a stream object as a parameter. When I attempt to compile this code I get the following error:
error C2660: 'System::IO::Stream::Dispose' : function does not take 0 arguments
I am using C++ 2005 Beta 2.
Any help appreciated
__
A little later, I was able to get it to compile with "System::IO::Stream ^pStream" but I am uncertain what the modifier ^ does when in the paramater list.
[634 byte] By [
bxs122] at [2007-12-16]
It's not a modifier. ^ says that this is a handle to a managed object. Like & says its a reference or * says its a pointer.
In fact using a managed object inthe way:
void test(ManagedObjectType obj)
{
}
Is not possible if it is not a value type. You must use the handle notation ^!
Martin
Martin Richter wrote: |
| It's not a modifier. ^ says that this is a handle to a managed object. Like & says its a reference or * says its a pointer. In fact using a managed object inthe way: void test(ManagedObjectType obj) { } Is not possible if it is not a value type. You must use the handle notation ^! Martin |
|
Thanx -- I'll have to look this one up, I am a C++ guy and new to some aspects of .NET. When you say handle to a managed object isn't that the same as saying a pointer to a managed object? Can a pointer to a managed object be passed as a parameter? Just curious since the ^ will work.
I am a C++ guy too, and I am learning hard to get the new aspects of C++/CLI and C# into my limited head storage :-)
Think about a handle to a managed objeat as a smart pointer! Its just a pointer were you do not have to take care, because the GC will do it. Also it says that this object lieaves in the managed Heap.
And no its not the same as a pointer... It is better to use the new word handle here.
And yes you can pass this "smart pointer" or better handle as a parameter or a reference. Passing it as a parameter was just the normal syntax we saw.
// Here as a reference
void test1(ManagedObject^ &refToHandle)
{
refToHandle = gcnew ManagedObject();
}
// Thats what we had: As a parameter
void test1(ManagedObject^ param)
{
}