I'm trying to understand how the hpp, cpp, and main all work together. for this example I'm working on a code that coverts ARGB to RGBA and I'm confused on what to put in each file. This is my code: color.hpp
using namespace std; #include #include #include #ifndef colors_hpp #define colors_hpp /* colors_hpp */ string getHex(); uint32_t fromArgb(); #endif
#include "colors.hpp" #include #include #include #include template struct Color < public: /* Works fine. */ Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) < buffer((r Color(const uint32_t argb) < buffer = fromArgb(argb); >inline uint32_t fromArgb(uint32_t argb) < return // Source is in format: 0xAARRGGBB ((argb & 0x00FF0000) >> 16) | //____RR ((argb & 0x0000FF00)) | //_GG_ ((argb & 0x000000FF) inline uint8_t getRed(void) const < return (buffer >> 0) & 0xFF; > inline uint8_t getGreen(void) const < return (buffer >> 8) & 0xFF; > inline uint8_t getBlue(void) const < return (buffer >> 16) & 0xFF; > inline uint8_t getAlpha(void) const < return (buffer >> 24) & 0xFF; > /* Works fine. */ std::string getHex(void) const < std::string result = "#"; char colorBuffer[255] = <>; // Order is intentionally end to beginning sprintf_s(colorBuffer, 255, "%.2X", getAlpha()); result.append(colorBuffer); sprintf_s(colorBuffer, 255, "%.2X", getBlue()); result.append(colorBuffer); sprintf_s(colorBuffer, 255, "%.2X", getGreen()); result.append(colorBuffer); sprintf_s(colorBuffer, 255, "%.2X", getRed()); result.append(colorBuffer); return result; > private: uint32_t buffer; >;
int main(int argc, char**argv)
I'm not able to understand where to use or call the struct or functions, and i'm really confused on what to put in hpp, cpp, and main files.