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.

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.