Re: How to pass function name as a parameter?
From: Russ Holsclaw (russ_at_holsclaw.nyet)
Date: 05/25/04
- Next message: MikeD: "Re: How to pass function name as a parameter?"
- Previous message: Duane Bozarth: "Re: How to pass function name as a parameter?"
- In reply to: Levan Jgarkava: "Re: How to pass function name as a parameter?"
- Next in thread: Levan Jgarkava: "Re: How to pass function name as a parameter?"
- Reply: Levan Jgarkava: "Re: How to pass function name as a parameter?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 25 May 2004 16:00:05 -0600
> There is also one question: what is the best method to convert overloaded
> index operators with return type of reference?
> for example:
> class A
> {
> private: int data[100];
> public: int& operator[] (int index) {return data[index];}
> }
>
> Now I can create function like this:
>
> Private data(100) As Integer
>
> Public Sub operator_index(ByVal index As Integer, ByVal NewValue As
Integer)
> data(index) = NewValue
> End Sub
>
I'm not sure what you mean by return type of reference, but if what you
want to do is have an object that acts like an array, you shouldn't
overlook what you can do with Properties, which don't really have a C++
counterpart.
----------in class clsArraything
Private data() As Integer
Private sub Class_Initialize()
redim data(0) as integer ' create a trivial array
end sub
Public Property Let value(ByVal index As Integer, ByVal NewValue As
Integer)
if index > ubound(data) then
redim preserve data(index)
end if
data(index) = NewValue
End property
Public Property Get value(byval index) as Integer
if index > ubound(data) then
value = 0 'pretend the array goes on forever, with zeroes
else
value = data(index)
end if
end property
------------- end of class module
Now, to use this class, you declare an instance of the object:
Dim Myarray as New clsArraything
' ... and then you can set something into the array thus:
Myarray.value(I) = 295
'... and then address it like this:
X = Myarray.value(I)
... so you can make an object, or rather a property of it, behave just like
an array variable. C++ doesn't really have anything like VB's properties.
Notice that what we have here is an "array-like" object that behaves as if
it didn't have an upper boundary. It expands according to the data that's
put into it. (dealing with negative indexes is an exercise for the
student!)
- Next message: MikeD: "Re: How to pass function name as a parameter?"
- Previous message: Duane Bozarth: "Re: How to pass function name as a parameter?"
- In reply to: Levan Jgarkava: "Re: How to pass function name as a parameter?"
- Next in thread: Levan Jgarkava: "Re: How to pass function name as a parameter?"
- Reply: Levan Jgarkava: "Re: How to pass function name as a parameter?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|