ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Weight=Weight+(Matrix<float>) x;
Type cast:
operator Matrix<float> ()
{
Matrix<float> x(rows,columns);
for(int i=0;i<rows;i++)
for(int j=0;j<columns;j++)
x.Array[i][j]=Array[i][j];
return x;
}
// not sure about the correctness of this thing
Please help me. Expecting quick responses.
Thanks to all the hearts that care to help me.
------
Edit:
Error: 'type cast' : cannot convert from 'class Matrix<int>' to 'class Matrix<float>'
No constructor could take the source type, or constructor overload resolution was ambiguous
This pops up template function has already been defined
error.
As u said I tried to be specific by overloading for the float and int types alone.that too resulted in the same error.
And x=x+Weight -- too gave the same error.
I would love to send u the headerfile containing these operations if u want.
Please help...
Thanks to dmail for ur sincere contribution to sort me out of this...
You have to separate the template declarations because the first is to open the scope of Matrix, and the second takes place within that scope.
Also, you should make your copy constructor, assignment operator, and + operator take a const Matrix; often times you will be given a const reference to copy, but if your operator doesn't take const it won't work. In other words, take references as const unless you can't do it otherwise.
ta0kira
To dmail:
Sure I will send my code by tomo.
I actually was discussing a situation where a type cast wasnt required. anyway i have found a problem and need to find a soln. So i will send it to u
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.