For ease I will split this section into relational operators and arithmetic operators. We can represent the relational operators using the following diagram
These operators will always return a boolean value which will be the result of some form of comparison.
Arithmetic operators will return an object of some type which depending upon the context may be either the same object or a new type of object. Later we will also add the += style operators which will mutate the current object rather than returning a value.
Equality Operators
In the case of the Vec3 class there are only two equality operator which make sense to implement, these are the == and != operators. Also we must ensure that we are doing correct comparison as we are storing floating point values. ( see here for an in depth discussion of floating point comparison ). For this example I'm going to generate a very simple FCompare macro which will be used to do a comparison via a simple epsilon error value.
//---------------------------------------------------------------------------------------------------------------------- /// @brief define EPSILON for floating point comparison //---------------------------------------------------------------------------------------------------------------------- #ifndef EPSILON const float EPSILON = 0.001f; #endif //---------------------------------------------------------------------------------------------------------------------- /// @brief FCompare macro used for floating point comparison functions //---------------------------------------------------------------------------------------------------------------------- #define FCompare(a,b) \ ( ((a)-EPSILON)<(b) && ((a)+EPSILON)>(b) )In the first example I will produce a "Member operator" for the equality operator, first in the .h file we declare the operator
bool Vec3::operator==(const Vec3 &_rhs) { return FCompare(m_x,_rhs.m_x) && FCompare(m_y,_rhs.m_y) && FCompare(m_z,_rhs.m_z); }As you can see in this case we do a component wise FCompare with the current object and the rhs value. We can test this using the following code from the previous examples
if(b==c) std::cout<<"b==c is true\n"; else std::cout<<"b!=c \n"; if(a==fromFloat) std::cout<<"a==fromFloat\n"; else std::cout<<"a!=fromFloat\n";Which gives the following output
testing equality operators b==c is true a!=fromFloatTo generate the != method we do the following
/// in .h /// @brief != operator bool operator!=(const Vec3 &_rhs); /// in .cpp bool Vec3::operator!=(const Vec3 &_rhs) { return !(*this==_rhs); }For the free function operator we have to write some additional code again to allow the free function access to the attributes. In this case we are going to write a method called isEqual ( note that my coding standard says this kind of method should be formed as a question as it returns a bool)
/// @brief function to test equality bool isEqual(const Vec3 &_rhs) const;The actual code for this class method will use the same FCompare macro as above and looks like this
bool Vec3::isEqual(const Vec3 &_rhs) const { return FCompare(m_x,_rhs.m_x) && FCompare(m_y,_rhs.m_y) && FCompare(m_z,_rhs.m_z); }The free function definitions of the == and != methods are now declared outside of the class but still in the .h file as follows
/// @brief free operator for equality testing bool operator ==(const Vec3 &_lhs, const Vec3 &_rhs); /// @brief free operator for equality testing bool operator !=(const Vec3 &_lhs, const Vec3 &_rhs);Finally we write the main function code, not that as they are no longer class methods it is no longer valid to mark the methods as const (in fact you get the following error with g++ error: non-member function 'bool operator==(const Vec3&, const Vec3&)' cannot have cv-qualifier )
bool operator ==(const Vec3 &_lhs, const Vec3 &_rhs) const { return _lhs.isEqual(_rhs); } bool operator !=(const Vec3 &_lhs, const Vec3 &_rhs) { return !_lhs.isEqual(_rhs); }
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. Python Training in Chennai
ReplyDeleteThis information is impressive; I am inspired by your post writing style & how continuously you describe this topic.... Java Training in Chennai | Python Training in Chennai
ReplyDelete
ReplyDeleteThis is my first visit to your blog, keep writing more content.
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Course in Chennai
JAVA Training in Chennai
German Classes in chennai
java training in adyar
This comment has been removed by the author.
ReplyDeleteNice post...Thanks for sharing..
ReplyDeletePython training in Chennai/
Python training in OMR/
Python training in Velachery/
Python certification training in Chennai/
Python training fees in Chennai/
Python training with placement in Chennai/
Python training in Chennai with Placement/
Python course in Chennai/
Python Certification course in Chennai/
Python online training in Chennai/
Python training in Chennai Quora/
Best Python Training in Chennai/
Best Python training in OMR/
Best Python training in Velachery/
Best Python course in Chennai/
Thank you for this informative blog
ReplyDeleteTop 5 Data science training in chennai
Data science training in chennai
Data science training in velachery
Data science training in OMR
Best Data science training in chennai
Data science training course content
Data science certification in chennai
Data science courses in chennai
Data science training institute in chennai
Data science online course
Data science with python training in chennai
Data science with R training in chennai
Thank you for excellent article.You made an article that is interesting.
ReplyDeleteAWS Solutions Architect courses in Bangalore with certifications.
https://onlineidealab.com/aws-training-in-bangalore/
This comment has been removed by the author.
ReplyDeleteExcellent post..
ReplyDeleteinplant training in chennai
inplant training in chennai
inplant training in chennai for it.php
Australia hosting
mexico web hosting
moldova web hosting
albania web hosting
andorra hosting
australia web hosting
denmark web hosting
inplant training in chennai
ReplyDeleteinplant training in chennai
inplant training in chennai for it.php
chile web hosting
colombia web hosting
croatia web hosting
cyprus web hosting
bahrain web hosting
india web hosting
iran web hosting
Very Nice...
ReplyDeleteinternship in chennai for ece students with stipend
internship for mechanical engineering students in chennai
inplant training in chennai
free internship in pune for computer engineering students
internship in chennai for mca
iot internships
internships for cse students in
implant training in chennai
internship for aeronautical engineering students in bangalore
inplant training certificate
nice.....it is use full...
ReplyDeleteaeronautical internship in india
free internship in chennai for mechanical engineering student
architectural firms in chennai for internship
internship in coimbatore for eee
online internships for cse students
mechanical internship certificate
inplant training report
internships in hyderabad for cse
internship for mba students in chennai
internship in trichy for cse
keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
ReplyDeletedigital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore
Taldeen is one of the best plastic manufacturing company in Saudi Arabia. They are manufacturing Handling Solutions Plastic products like Plastic Pallets and plastic crates. Here is the link of the product
ReplyDeleteHandling Solutions
Plastic Pallets
GrueBleen is one of the Branding and Marketing agency Based in Riyadh- Saudi Arabia. The main functions of GrueBleen is Advertising, Branding, Marketing, Office Branding, Exhibition Management and Digital Marketing. Visit the below link to know more about GrueBleen Creative Club.
Branding Agency Riyadh
Marketing Agency Riyadh
Agriculture Solutions – Taldeen is a plastic manufacturing company in Saudi Arabia. They are manufacturing agricultural plastic products like greenhouse cover and hay cover. Visit the below link to know more details
Agriculture Solutions
Greenhouse Cover
GrueBleen – One of the best social media marketing agency in Riyadh- Saudi Arabia. Visit here for the all service details of GrueBleen.
Social Media Marketing Agency | Social Media Agency In Saudi Arabia | Social Media Agency In Riyadh | Social Media Agency in Jeddah |
Here is the colleges details to study in Bangalore. You can select the best college details from the below mentioned courses that you love to study. The list of colleges are only in Bangalore, so, if you are looking to study in Bangalore, just click the below mentioned links.
ReplyDeleteBSc Medical Imaging Technology Colleges in Bangalore | Medical Imaging Technology Colleges in Bangalore | BSc Optometry Colleges in Bangalore | Optometry Colleges in Bangalore |BSc Renal Dialysis Colleges in Bangalore | Renal Dialysis Technology Colleges in Bangalore |BSc Respiratory Care Technology Colleges in Bangalore | Respiratory Care Colleges in Bangalore |BSc Cardiac Care Technology Colleges in Bangalore | Cardiac Care Colleges in Bangalore |BSc Perfusion Technology Colleges in Bangalore | Perfusion Technology Colleges in Bangalore |
I just wanted to let you know that the piece you shared with us is pretty unique and authentic. I am going to keep browsing this blog.
ReplyDeleteAndroid Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery
Really awesome blog!!! I finally found great post here.I really enjoyed reading this article. It's really a nice experience to read your post.
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
Great Article
ReplyDeleteFinal Year Projects in Python
Python Training in Chennai
FInal Year Project Centers in Chennai
Python Training in Chennai
Right here is the right website for anyone who really wants to find out about this topic. You know so much its almost hard to argue with you (not that I personally would want to…HaHa). You definitely put a brand new spin on a topic that's been written about for ages. Wonderful stuff, just wonderful!
ReplyDeletetech gadget
Ogen Infosystem is one of the best Website Designing and PPC Company in Delhi, India. Here you will well experience web designers and developers to provide a great website for your business. Our PPC Experts generate leads to your business products at an affordable price.
ReplyDeletePPC Company in Delhi
I am glad to post a worthy article about the German Language Course and IELTS Coaching from KCR consultants, this may change your career growth and language skill.
ReplyDeleteKCR CONSULTANTS
KCR CONSULTANTS
Thanks for posting the best information and the blog is very helpful.digital marketing institute in hyderabad
ReplyDeleteInformative blog
ReplyDeletebest digital marketing institute in hyderabad
thanks for sharing this information with us
ReplyDeletefull stack developer course
full stack developer course in Bangalore
I truly appreciate just perusing the entirety of your weblogs. Just needed to educate you that you have individuals like me who value your work. Unquestionably an extraordinary post. Caps off to you! The data that you have given is exceptionally useful.data science training in chennai
ReplyDeleteonline training in java
ReplyDeleteonline training on java
Thanks for sharing I really loved this article the way you presented is really amazing this helped me to gain a lot of knowledge
ReplyDeleteBest Software training institues
cool stuff you have and you keep overhaul every one of us data science course in mysore
ReplyDeleteInfycle Technology, No.1 Software Training Institute in Chennai, afford best Data Science training in Chennai and also provide technical courses like Oracle, Java, Big data, AWS, Python, DevOps, Digital Marketing, Selenium Testing, etc., and we also provide the best training from the best technical trainers and after completion of training students will be able to crack the jobs on top MNC’s. for more information call 7504633633.
ReplyDeleteExtremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.data scientist course in warangal
ReplyDeleteInfycle Technologies, the No.1 software training and job placement institute offers the affordable Oracle training in Chennai for techies, students and freshers. Along with the Oracle, other top demanding software courses such as Python, Power BI, Digital Marketing, Data Science, Big Data, Java, AWS, Machine Learning, will be taught here. Dial 7502633633 to get more info and a free demo.
ReplyDeleteJump into a great learning experience of learning AWS Training in Chennai from Infycle Technologies, the finest software training Institute in Chennai. Also, a proper place to learn other technical courses like Cyber Security, Graphic Design and Animation, Block Security, Java, Cyber Security, Oracle, Python, Big data, Azure, Python, Manual and Automation Testing, DevOps, Medical Coding etc., and here we provide well-experienced trainers with excellent training to the freshers. And we also provide 100+ Live Practical Sessions with Real-Time scenarios which helps the students in learning the technical stuff easily and they are able to crack interviews in top MNC’s with an amazing package. for more queries approach us on 7504633633, 7502633633.
ReplyDeleteI'm genuinely getting a charge out of scrutinizing your richly formed articles. Apparently you consume a huge load of energy and time on your blog. I have bookmarked it and I am expecting scrutinizing new articles. Continue to do amazing.data science course in ghaziabad
ReplyDeleteI truly appreciate just perusing the entirety of your weblogs. Just needed to educate you that you have individuals like me who value your work. Unquestionably an extraordinary post. Caps off to you! The data that you have given is exceptionally useful.data scientist course in bhopal
ReplyDelete