overloading 'address of' operator
Let's say we have a 'Vec' class that it is defined using the vector class. Also, let's assume i have overloaded the function operator, so that i can do the following:
a(0) = 1;
a(1) = 4;
... and so on.
what the operator () returns is just this:
where 'i' is the index 0,1,...... and  is because the object of the class is a vector object.
Having say that, i would like to obtain the address of the first element in the object of the class 'Vec' as I would do it in the vector class, that is: &v(0), where v is an object of the vector class: vector<double> v(2)
Can I do the same with a? that is: &a(0)
I have read that overloading the operator & is not a good idea, how can i do the same in other way?
Re: overloading 'address of' operator
ultimately what I want to do is to use my 'Vec' class in conjunction with a matrix class 'Mat', where the objects are accessed as m(i,j), so I want to be consistent if i do this:
so, this way i can use in both cases () and not:
My problem is I must have the address of the first member of the 'Vec a' to do the following in order to pass the address to a external library which is written in C:
p = &a(0);
Now, since my 'vector a' is not directly an object of the vector class, i think with the above i will not obtain the address unless I overload the '&' operator. If so, how can i do that? or how can i do something similar without overloading the '&' operator?
|All times are GMT +5.5. The time now is 10:01.|