Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Teste sobrecarga de operadores
#include <iostream> #include <cstring> using namespace std; typedef unsigned char UInt8; typedef signed char Int8; typedef char Char; class FirmVersion { public: FirmVersion( UInt8 p_version, UInt8 p_subVersion, Char p_revision ); ~FirmVersion(){}; bool operator>( const FirmVersion &p_other ); bool operator<( const FirmVersion &p_other ); bool operator==( const FirmVersion &p_other ); private: Int8 Compare( const FirmVersion &p_versionA, const FirmVersion &p_versionB ); UInt8 ProductFamily; //!< @brief Identificador da família do produto UInt8 Version; //!< @brief Versão do firmware. ( 0 - 9 ) UInt8 SubVersion; //!< @brief subversão do firmware. ( 0 - 99 ) Char Revision; //!< @brief Revisão do firmware. ( A - Z ) }; FirmVersion::FirmVersion( UInt8 p_version, UInt8 p_subVersion, Char p_revision ) : Version( p_version ), SubVersion( p_subVersion ), Revision( p_revision ) { } bool FirmVersion::operator>( const FirmVersion &p_other ) { return ( Compare( *this, p_other) > 0 ); } bool FirmVersion::operator<( const FirmVersion &p_other ) { return ( Compare( *this, p_other ) < 0 ); } bool FirmVersion::operator==( const FirmVersion &p_other ) { return ( Compare( *this, p_other ) == 0 ); } Int8 FirmVersion::Compare( const FirmVersion &p_versionA, const FirmVersion &p_versionB ) { UInt8 vA[3] = { p_versionA.Version, p_versionA.SubVersion, p_versionA.Revision }; UInt8 vB[3] = { p_versionB.Version, p_versionB.SubVersion, p_versionB.Revision }; return memcmp( vA, vB, 3 ); // Retorna 1 se vA>vB, -1 se vA<vB, 0 se vA==vB } int main() { FirmVersion vA( 2, 5, 'B' ); FirmVersion vB( 2, 5, 'C' ); if ( vA == vB ) std::cout << "vA igual a vB" << endl; else { if ( vA > vB ) std::cout << "vA maior que vB" << endl; else std::cout << "vA menor que vB" << endl; } return 0; }
run
|
edit
|
history
|
help
0
cccc
Exploring the Transform Function and Operator Classes
Web Browser History - SET
Kolokwium_2011_z12
Fractional Knapsack
Job Scheduling
at.cpp
Deque EvenOdd
BinTree playground
BinTraversal