Language : C++

I have had a bit of confusion with overloading the script operator. Not really sure on how to incorporate the operator. I am almost finished coding a program assignment except for this problem with the srcipt operator.

The script operator info taken directly from assignment instructions is the following:


The indexing operator should be overloaded to provide accessor methods for the class. Subscript 0 should provide access to the x component value of the vector; subscript 1 to the y component and subscript 2 to the z component. Subscript values other than 0, 1, or 2 produce undefined results. For speed, no error checking needs to be done.

The choice of how the data members are implemented in the class could greatly affect the complexity of overloading this particular operator.

Don't forget that this operator needs to be overloaded twice, once for getting a value and once for setting a value".

This is what the class looks like.

class V
                // Friends
friend V operator*(float, const V &);
friend V operator*(const V &, float);
friend ostream & operator<<(ostream & , const V &);

                // Class data members
float x,
                // Method Prototypes
V(int  , int , int);
bool operator ==(const V& r);
V operator +(const V & right); 
V operator -(const V & right);
float operator*(const V & right);

With the data members of the class set as float, how can the overloaded script operator come together to work with float members ? How can the overloaded script operator be coded?

Edited by Nick Evan: Added code-tags

8 Years
Discussion Span
Last Post by Dave Sinkula
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.