Accessing array of an object

I am overloading the * operator and I am having trouble accessing the array of the object that the method is called on.

ex result = a *b; I am having trouble getting a.

I have to get the whole array and call another method on it to times that array with a single digit.

1
2
3
4
5
6
7
8
9
10
11
12
13
  bigint bigint::operator*(bigint b){

  bigint result ;
  int power = 0 ;

  for(int i = ARRAYSIZE-1;i>0;--i){

    result = result +  a.timesdigit(b.bigintArray[i]);

  }
  return result ;
}


that a needs to be replaced with something but I do not know what.
closed account (Dy7SLyTq)
i think your looking for *this. otherwise a would be considered the current object (assuming that a is a bigint)
I also suggest looking up how to pass by reference (pass variables by reference), because it is much more efficient, and it doesn't create new memory.

Another thing: you call it a "method", and that's not correct. Java has methods, C++ does not. This is a class you are modifying.

here is the prototype for passing by reference to get you started:

bigint operator*(const bigint&); //also look up constant correctness

Also, I would consider ONLY creating addition/subtraction functions, since multiplication/division is only an extension of them, and use those in multiplication/division processes. Of course, this only somthing to consider.
closed account (Dy7SLyTq)
actually... class functions are also called methods in c++. ive found it to be a pretty common oop term
you call it a "method", and that's not correct. Java has methods, C++ does not.

Um... what? Of course C++ has methods! Member functions of a class have always been known as "methods".
@DTS
Huh, that's interesting.

"Method" is general to OOP, "member function" is specific to C++. Which you use depends on whether you're discussing general OOP or specific aspects of C++.
closed account (Dy7SLyTq)
"Method" is general to OOP, "member function" is specific to C++. Which you use depends on whether you're discussing general OOP or specific aspects of C++.


point is... member is a valid term
In C++, member functions literally are (static) members of classes.

In Java, the semantics are entirely different, and methods are technically not considered to be actual members of classes (as seen with the Reflection API).
closed account (Dy7SLyTq)
In C++, member functions literally are (static) members of classes.

well actually i have seen it used to decribe functions located in a class, not just static ones. bajarne stroustrop uses the term too.
1
2
3
4
5
6
struct Ex
{
    void f(); //member function
    std::function<void()> g; //member std::function
    void (*h)(); //member pointer to function
};
In this case g and h are only accessible from an instance of the class, whereas f is accessible from a static context:
1
2
//no instance of Ex exists
auto my_f = &Ex::f;
http://ideone.com/aKV95D
http://ideone.com/B0dOLq
Last edited on
closed account (Dy7SLyTq)
sorry my mistake... the caffiene is wearing off, and thought you said method in the quote. my bad
Topic archived. No new replies allowed.