Click here to Skip to main content
16,017,448 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Looking for opinions on currency handling.... Pin
Jeremy Falcon3-Sep-24 15:53
professionalJeremy Falcon3-Sep-24 15:53 
GeneralRe: Looking for opinions on currency handling.... Pin
Mircea Neacsu3-Sep-24 16:07
Mircea Neacsu3-Sep-24 16:07 
GeneralRe: Looking for opinions on currency handling.... Pin
Jeremy Falcon3-Sep-24 17:31
professionalJeremy Falcon3-Sep-24 17:31 
QuestionADDENDUM How to display full 4 binary bits - after QString "number" option converts string to int. including hexadecimal strings. Pin
jana_hus30-Aug-24 7:39
jana_hus30-Aug-24 7:39 
QuestionRe: How to display full 4 binary bits - after QString "number" option converts string to int. Pin
Richard MacCutchan30-Aug-24 8:05
mveRichard MacCutchan30-Aug-24 8:05 
AnswerRe: REOPEN How to display full 4 binary bits - after QString "number" option converts string to int. including hexadecimal strings. Pin
Richard MacCutchan3-Sep-24 21:56
mveRichard MacCutchan3-Sep-24 21:56 
Questionwrapping enum in namespace ? Pin
Maximilien29-Aug-24 3:37
Maximilien29-Aug-24 3:37 
AnswerRe: wrapping enum in namespace ? Pin
k505429-Aug-24 5:43
mvek505429-Aug-24 5:43 
You don't need to go as far as a namespace, just a struct will do.
C++
struct Color {
   enum value { Red, Yello, Blue };
};

int main()

{
    Color::value box = Color::value::Red;
}

If you want to be able to print Color::Red as a string, it's a bit more involved
C++
#include <iostream>

struct Color {
    enum hue { Red, Yellow, Blue } value;
    std::string as_string() {
        std::string color;
        switch(value) {
            case Red :    color = "Red";     break;
            case Yellow : color = "Yellow";  break;
            case Blue :   color = "Blue";    break;
        };
        return color;
    }
    Color(Color::hue val) : value(val) {};
    bool operator==(const Color&other) {
        return value == other.value;
    }
    friend std::ostream& operator<<(std::ostream& os, const Color& color);
};

std::ostream& operator<<(std::ostream& os, const Color& color)
{
    os << color.value;
    return os;
}

int main()
{
    Color x = Color::Red;
    Color y = Color::Blue;
    std::cout << x << '\n';
    std::cout << x.as_string() << '\n';
    if(x == y)
        return 1;
    else
        return 0;
}
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown


modified 29-Aug-24 11:50am.

GeneralRe: wrapping enum in namespace ? Pin
Maximilien29-Aug-24 6:41
Maximilien29-Aug-24 6:41 
QuestionThis should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 11:12
professionalJeremy Falcon28-Aug-24 11:12 
AnswerRe: This should be an easy question... 128-bit blues. Pin
k505428-Aug-24 12:04
mvek505428-Aug-24 12:04 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 12:21
professionalJeremy Falcon28-Aug-24 12:21 
AnswerRe: This should be an easy question... 128-bit blues. Pin
Mircea Neacsu28-Aug-24 14:47
Mircea Neacsu28-Aug-24 14:47 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 15:03
professionalJeremy Falcon28-Aug-24 15:03 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Mircea Neacsu28-Aug-24 15:11
Mircea Neacsu28-Aug-24 15:11 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Jeremy Falcon28-Aug-24 15:43
professionalJeremy Falcon28-Aug-24 15:43 
GeneralRe: This should be an easy question... 128-bit blues. Pin
Mircea Neacsu28-Aug-24 15:46
Mircea Neacsu28-Aug-24 15:46 
QuestionOwn border in client area Pin
john563226-Aug-24 19:59
john563226-Aug-24 19:59 
AnswerRe: Own border in client area Pin
Richard MacCutchan26-Aug-24 22:10
mveRichard MacCutchan26-Aug-24 22:10 
AnswerRe: Own border in client area Pin
Maximilien27-Aug-24 8:22
Maximilien27-Aug-24 8:22 
QuestionData file Pin
Calin Negru26-Aug-24 2:36
Calin Negru26-Aug-24 2:36 
AnswerRe: Data file Pin
Maximilien26-Aug-24 3:29
Maximilien26-Aug-24 3:29 
AnswerRe: Data file Pin
k505426-Aug-24 3:30
mvek505426-Aug-24 3:30 
AnswerRe: Data file Pin
Dave Kreskowiak26-Aug-24 3:32
mveDave Kreskowiak26-Aug-24 3:32 
GeneralRe: Data file Pin
Calin Negru26-Aug-24 4:20
Calin Negru26-Aug-24 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.