1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

overloading 'address of' operator

Discussion in 'C++' started by aortizb, Aug 27, 2009.

  1. aortizb

    aortizb New Member

    Joined:
    Sep 12, 2008
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    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:

    Vec a;

    a(0) = 1;
    a(1) = 4;
    ... and so on.

    what the operator () returns is just this:

    return (*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?

    thanks.
     
  2. aortizb

    aortizb New Member

    Joined:
    Sep 12, 2008
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    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:

    m(2,3)*a(4)

    so, this way i can use in both cases () and not:

    m(2,3)*a[4]

    see?

    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:

    double *p;

    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?
     

Share This Page