-
October 13th, 2006, 09:14 AM
#16
Re: C++ Aha! Moments
Originally Posted by Zaccheus
Or if you have been struggling with a problem and then read something helpful in a book!
IMO that's more an "Oh! Of course!".
- petter
-
October 13th, 2006, 09:44 AM
#17
Re: C++ Aha! Moments
Here are few:
- Discovering references.
- Discovering STL.
- Discovering RTTI (took some time to find out I need to check the RTTI check box in the compiler but after that it was ok )
- Last one that is not related to C++ but more to Win Api is that I am always amazed that no matter what you need to do there is an api that does it, sometimes the name can be misleading so its hard to find them but believe me its exists and it “there”.
Cheers
-
October 13th, 2006, 09:47 AM
#18
Re: C++ Aha! Moments
Originally Posted by wildfrog
IMO that's more an "Oh! Of course!".
- petter
Sometimes, yes.
-
October 13th, 2006, 09:57 AM
#19
Re: C++ Aha! Moments
My Aha ! moment was when I finally sat down with C# and stopped being so prejudiced, thinking it was just VB6 with a C++ syntax. I've never looked back...
Darwen.
-
October 13th, 2006, 12:41 PM
#20
-
October 14th, 2006, 03:25 AM
#21
Re: C++ Aha! Moments
My Aha list (I can't remember dates, my brain is really not designed for that) in an approximatively chronological order:
- Constructors, destructors & RAII (I didn't know the term at this date).
- Multiple inheritance.
My C++ teacher in DEUG 2 (I had 4 months of C++ taught at university, though STL or dynamic memory allocation were not introduced in these courses) told me that a class could not inherit from more than one class when I asked whether it was possible (after all, a thing can be more than the expression of a single abstraction at a time). I trusted him, until I discovered that he was wrong later. - streambuf and its role in iostreams.
I discovered that this design allows an indefinite extensibility of the number of streambufs, without any depency on iostreams classes, and permits an extensibility of the iostream classes without any modification of streambuf classes.
It's even easy to create new iostream-like classes based on a streambuf* pointer.
And the streambuf class is designed for extreme speed (no virtual function call for sputc or sgetc), even though its power is not diminished by this design choice.
The only pain with streambuf are the incredibely ugly and inconsistent member names. - Pointer to members (data members as well as function members).
Even though it's not a feature used everyday, it's representative of the freedom that C++ gives to programmers. From this date, I have feeled very friendly with C++. - Templates & template meta-programming.
Very impressive. - Understanding really the concepts behind C++ types & scope rules.
Reference types can be used almost anywhere (e.g. members, return value), and not only as function parameters.
Function types can be typedefed, and exists on they own.
You can create pointers to array, references to array, references to functions...
You can declare external linkage functions & data in any block of code.
Code:
typedef int intOperator(int x,int y);
int main() {
intOperator add, sub, multiply, divide;
return multiply(2,add(5,3));
}
int add(int x,int y)
{
return x+y;
}
int multiply(int x, int y)
{
return x*y;
}
- The iterator abstraction that I discovered with the STL. The "Aha" applied to the abstraction of iterators, not really to the STL containers themselves.
- Private inheritance.
- Exception correctness, reading Herb Sutter's GotW. Very impressive. A new way of thinking & programming.
Deeper understanding of the roles of swap, RAII and exception guarantees.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
October 14th, 2006, 01:46 PM
#22
Re: C++ Aha! Moments
What a great discussion here. Let me join with 5 C++ Aha! moments, in a chronological order
- discovering C++ programs written for Borland C++ 3.1 don't run in VisualC++, especially if they use headers like <graphics.h> or <dos.h>. (2001)
- discovering in C++ structs can have member functions; I used to thought of structs in the C way, and I was quite surprized that nobody told me in college what structs in C++ really are; (2002)
- discovering pointer this is not a member of a class but a parameter to the non-static member functions; I almost felt betrayed, it made me wonder what good for were my university studies; I always lived with the impression, that pointer this is some special default member of classes. This was probably my greatest revelation. Suddenly, the C++ releaveled to me in a different light. (2003)
- discovering STL and especially std::vector and std::string; it really made my programs look totally different. Discovering how nice functors are also came as I was starting to use STL. (2005)
- realizing that CPP was the most suitable 3-characters combination that would define me so that I could put on my car's identification plate. That made a lot of people laught. (2006)
-
October 14th, 2006, 04:17 PM
#23
Re: C++ Aha! Moments
1) 2004 understanding that class`s may have ancestors
2) 2004 getting idea about functions overlaoding
3) 2005 at last I have understand why we need virtual functions
God could improve essentially a
human nature, but he
was too anxious with compatibility
with the monkey.
(Eugeny Goldberg)
-
October 14th, 2006, 05:07 PM
#24
Re: C++ Aha! Moments
Originally Posted by cilu
- discovering pointer this is not a member of a class but a parameter to the non-static member functions; I almost felt betrayed, it made me wonder what good for were my university studies; I always lived with the impression, that pointer this is some special default member of classes. This was probably my greatest revelation. Suddenly, the C++ releaveled to me in a different light. (2003)
And that "const" at the end of a function signature actually makes sense...
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
October 14th, 2006, 09:35 PM
#25
Re: C++ Aha! Moments
I was coding in 'C' before taking up C++ 16 years ago. So here is my contribution.
- Discovering that C++ isn't just 'C' with some extra syntax.
- Using STL for the first time, and realizing I didn't need to code all of those data structures, string classes, and algorithms again from scratch.
- Templates and meta-programming.
- gcc is not a toy compiler.
Regards,
Paul McKenzie
-
October 15th, 2006, 03:27 AM
#26
-
October 15th, 2006, 05:57 AM
#27
Re: C++ Aha! Moments
when the the message I sent with winsock actually got the the other end .
Rich
Visual Studio 2010 Professional | Windows 7 (x64)
Ubuntu
-
October 15th, 2006, 08:15 AM
#28
Re: C++ Aha! Moments
Originally Posted by Graham
And that "const" at the end of a function signature actually makes sense...
Yes, of course. It makes a lot of sense.
Originally Posted by ovidiu
Next, you should try MFC...
Yes, but MFC is written in C++, so...
-
October 15th, 2006, 11:29 AM
#29
Re: C++ Aha! Moments
I would like to rectify this item:
Originally Posted by me
Aha...
- ... Windows API is something cool! Death to console applications!
Better sounds:
Aha...
- ... "WinMain" is for making applications; "main" is for teaching teachers.
-
October 15th, 2006, 12:06 PM
#30
Re: C++ Aha! Moments
1. Discovering CG. Besides the emotional attachements, CG got me my first US$ earning job through the "Looking for Job" forum. The client happended to browse CG and had contacted me.
2. Discovering MFC. Actually I learned C++ through MFC. My father's friend had by accidently left the book "Mastering Visual C++ 6.0" by Michael J. Young in my house. Thinking that he would be back for the book any time I literally copied the whole book (more than 1000 pages) by hand. I even copied the code listings. But the friend didn't ask for that book. I still have the book and also the hand copied version. It's hard to believe but this is true.
3. Understanding virtual functions, pointers and references.
4. Understanding copy constructors.
5. Dynamic casts
6. Knowing the usefulness of Design Patterns.
7. Recently upon being stumbled with "Modern C++ Design" and understanding the usefulness of Policies.
If there is no love sun won't shine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|