Click here to Skip to main content
15,910,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Division By Zero Exception Pin
ForNow31-May-12 12:44
ForNow31-May-12 12:44 
GeneralCWinThread::Run works by turning optimization off #pragma optimize("",on) Pin
ForNow31-May-12 18:24
ForNow31-May-12 18:24 
AnswerRe: Division By Zero Exception Pin
Albert Holguin1-Jun-12 4:31
professionalAlbert Holguin1-Jun-12 4:31 
QuestionExtend std::string functionality Pin
forkbomber31-May-12 2:46
forkbomber31-May-12 2:46 
AnswerRe: Extend std::string functionality Pin
Chris Losinger31-May-12 3:27
professionalChris Losinger31-May-12 3:27 
AnswerRe: Extend std::string functionality Pin
Nemanja Trifunovic31-May-12 5:09
Nemanja Trifunovic31-May-12 5:09 
GeneralRe: Extend std::string functionality Pin
Albert Holguin31-May-12 9:56
professionalAlbert Holguin31-May-12 9:56 
AnswerRe: Extend std::string functionality PinPopular
Aescleal31-May-12 6:04
Aescleal31-May-12 6:04 
Write a set of free functions that take const string references and spit out strings modified the way you want. There are a couple of observations here...

First one is that just because a function isn't a member of a class doesn't mean that it violates some great principle of OO. A free function can be as much a part of a class's interface even if it's not a member:
C++
class A
{
    public:
        A &operator+=( const A &add_to );
};

A operator+( const A &a, const A &b )
{
    A temp( a );
    temp += b;
    return temp;
}
In this example the freestanding operator+ is very much part of A's interface. As is the usual practice of declaring an insertion and/or extraction operator to do input or output:
C++
class B
{
    public:
        friend std::ostream &operator<<( std::ostream &str, const B &print_me );
        friend std::istream &operator>>( std::ostream &str, const B &load_me );
};
Second one is that C++ isn't just an OO language. OO is probably the dominant idiom but even hardcore OO programmers use a fair number of generic techniques e.g:
C++
std::string to_upper( const std::string &source )
{
    std::string upper_case( source.size(), 0 );
    std::transform( begin( source ), end( source), begin( upper_case ), toupper );
    return upper_case;
}
and:
C++
std::string &to_upper_in_place( std::string &upper_case_me )
{
    std::string temp = to_upper( upper_case_me );
    std::swap( temp, upper_case_me );
    return upper_case_me;
}
They're both free functions but the second works very much like you'd defined a member of std::string.

Anyway, I've gone on enough. The points I was trying to make are:

- free functions can be part of a class's interface
- if a class hasn't been built to be extended by inheritance (which std::string isn't) then you have to use free functions to extend it

modified 31-May-12 12:40pm.

GeneralRe: Extend std::string functionality Pin
CPallini31-May-12 8:02
mveCPallini31-May-12 8:02 
GeneralRe: Extend std::string functionality Pin
Richard MacCutchan31-May-12 21:32
mveRichard MacCutchan31-May-12 21:32 
GeneralRe: Extend std::string functionality Pin
Aescleal1-Jun-12 0:51
Aescleal1-Jun-12 0:51 
QuestionHow to create your own Remote Desktop Application in Visual C++ or MFC Pin
Member 905298531-May-12 2:41
Member 905298531-May-12 2:41 
AnswerRe: How to create your own Remote Desktop Application in Visual C++ or MFC Pin
Richard MacCutchan31-May-12 3:54
mveRichard MacCutchan31-May-12 3:54 
AnswerRe: How to create your own Remote Desktop Application in Visual C++ or MFC Pin
Richard Andrew x6431-May-12 4:50
professionalRichard Andrew x6431-May-12 4:50 
AnswerRe: How to create your own Remote Desktop Application in Visual C++ or MFC Pin
Albert Holguin31-May-12 9:48
professionalAlbert Holguin31-May-12 9:48 
AnswerRe: How to create your own Remote Desktop Application in Visual C++ or MFC Pin
Rolf Kristensen31-May-12 23:21
Rolf Kristensen31-May-12 23:21 
Questionanimation in opengl Pin
appollosputnik31-May-12 1:37
appollosputnik31-May-12 1:37 
AnswerRe: animation in opengl Pin
enhzflep31-May-12 2:29
enhzflep31-May-12 2:29 
GeneralRe: animation in opengl Pin
appollosputnik31-May-12 3:12
appollosputnik31-May-12 3:12 
GeneralRe: animation in opengl Pin
enhzflep31-May-12 3:16
enhzflep31-May-12 3:16 
GeneralRe: animation in opengl Pin
Richard MacCutchan31-May-12 3:46
mveRichard MacCutchan31-May-12 3:46 
GeneralRe: animation in opengl Pin
enhzflep31-May-12 3:49
enhzflep31-May-12 3:49 
GeneralRe: animation in opengl Pin
Richard MacCutchan31-May-12 3:53
mveRichard MacCutchan31-May-12 3:53 
GeneralRe: animation in opengl Pin
enhzflep31-May-12 4:04
enhzflep31-May-12 4:04 
GeneralRe: animation in opengl Pin
Richard MacCutchan31-May-12 4:18
mveRichard MacCutchan31-May-12 4:18 

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.