473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Overloading ~ operator at 2x2 matrix (determinant)

Hey,
I'm having trouble overloading the ~ operator (the determinant of the matrix) in a case of 2x2 matrices. So i have a matrix class, with the constructor, overloading +, += and ~ operators. the first two are working but I don't know how to overload the ~ one.
here's what I have:
matrix matrix::operator~(matrix &m) {
double x;
x=(m.a11*m.a22)-(m.a12*m.a21);
return x;

of course it's not working cause i can't return a double value in a matrix class. Second of all it says that ~unary operator has too many parameters. But then how do I make a matrix class return only 1 parameter? (since the determinant is only one number).
thanks!
Nov 9 '08 #1
1 4431
Ganon11
3,652 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. matrix matrix::operator~(matrix &m) {
  2. double x;
  3. x=(m.a11*m.a22)-(m.a12*m.a21);
  4. return x;
The determinant is performed on 1 matrix, so you don't need to pass in another matrix. That is, you'll never have to deal with an expression like "mat1 ~ mat2;", but instead, "~mat1". Just deal with the this pointer to get to your elements.

To return a double instead of a matrix, just change the return value. Right now, you've told it you're returning a matrix.
Nov 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Andre | last post by:
Hi, I have a class which contains a two-dimensional array. I need to overload something like the operator so that I'm able to access the internal array elements via the class object. For...
51
by: Jojo | last post by:
Is there any way to get to the left-hand side of an operator? Consider the following (this is not meant to be perfect code, just an example of the problem): class Matrix { public: int data;...
2
by: Steffen | last post by:
Hi, is there a simple way to use operators overloaded in some class for objects of a derived class? In my example I have a class Matrix that represents 2x2 matrices, and I overloaded...
5
by: | last post by:
Hi all, I have a function: mat4 operator * (const float scalar); (matrix times integer) Is there a way that I could multiply an int by a matrix, as opposed to only a matrix by an int?
1
by: atomik.fungus | last post by:
Hi, as many others im making my own matrix class, but the compiler is giving me a lot of errors related to the friend functions which overload >> and <<.I've looked around and no one seems to get...
14
by: James Stroud | last post by:
Hello All, I'm using numpy to calculate determinants of matrices that look like this (13x13):
1
by: xkenneth | last post by:
Hi, I'm writing a sparse matrix class for class and I cannot seem to get operator overloading to work properly. I've overloaded an operator with the code here. matrix operator +(matrix one,...
4
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Operator overloads are just like any other member function, you can make them do whatever you want. However, of course, we might expect them to behave in a certain way. The ++ operator should...
9
by: curiously enough | last post by:
I need a practical method to find the eigenvalues of a matrix in C++ because the one I know(the only one I know) is to subtract the elements of the diagonal by the eigenvalue and then find the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.