954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Classes and assignment operator

I have a class (for the mathematically inclined, it's a tensor class that allows me to work with tensors of any rank and dimension), and I'm trying to set up assignment in a particular way, but having trouble.

The idea comes from the vector class. With that, you can retrieve a particular element using [iline]vector.at(n)[/iline] and also set that element by using [iline]vector.at(n)=value[/iline].

Currently, the class has a member [iline]operator(int i, ...)[iline] that will retrieve the value I want from the array *T where all the elements are stored, but in order to set them I have to call tensor.T[index]. The problem is that index isn't physically meaningful (to get index from the coordinates requires a messy sum), whereas calling tensor(i, ...) will grab the proper coordinates. I've tried overloading with [iline]operator(FLOAT val, int i, ...)[iline] where val is the value I want to set it to, but gcc complains about ambiguity (I would say from recasting, as you can pass an int as a float without error and such).

The long and short of it is I'd like to know how I can define a member that operates like the vector at()= method.

Note I've tried looking at the source and have attempted to recreate it with no luck.

mbarriault
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

Hrm... I can't seem to find the full source code, just the header files. Could you be clearer and how to find it?

mbarriault
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

Yeah, got Boost source from the repositories, but didn't help much.

Fortunately, out of randomness, I simply (de?)referenced the return value as so

FLOAT& tensor::operator()(int i, ...);


And it worked perfectly! Thanks for the help anyway!

mbarriault
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You