G
Guest
Using Visual Studio 2005, I'm trying to create a simple unmanaged C++ class
that will be called from a VB application. I've got the class working using
basic functions, but I'd like to overload the "=" operator so the VB app can
assign values directly to the class. When I use "operator=", VB tells me
that I can't assign an integer to my class.
Here's what I've got:
#pragma once
using namespace System;
namespace Server {
public ref class Test2
{
private:
int iValue;
public:
void SetVal(int Value) {
iValue = Value;
}
int GetVal(void) {
return iValue;
}
int operator= (int Value) {
iValue = Value;
return iValue;
}
};
}
This is the Visual Basic portion:
Dim obj1 As New Server.Test2
obj1.SetVal(8) 'This part works!
Debug.Print(obj1.GetVal.ToString)
obj1 = 10 'This statement says: Value of type
'Integer' cannot be converted to 'Server.Test2'.
Debug.Print(obj1.ToString) 'This fails, too.
that will be called from a VB application. I've got the class working using
basic functions, but I'd like to overload the "=" operator so the VB app can
assign values directly to the class. When I use "operator=", VB tells me
that I can't assign an integer to my class.
Here's what I've got:
#pragma once
using namespace System;
namespace Server {
public ref class Test2
{
private:
int iValue;
public:
void SetVal(int Value) {
iValue = Value;
}
int GetVal(void) {
return iValue;
}
int operator= (int Value) {
iValue = Value;
return iValue;
}
};
}
This is the Visual Basic portion:
Dim obj1 As New Server.Test2
obj1.SetVal(8) 'This part works!
Debug.Print(obj1.GetVal.ToString)
obj1 = 10 'This statement says: Value of type
'Integer' cannot be converted to 'Server.Test2'.
Debug.Print(obj1.ToString) 'This fails, too.