Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

I'm (re)learning C++. Ask me anything.

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 10:45 AM
Original message
I'm (re)learning C++. Ask me anything.
(But first, if the question is "what's C++", let me give the answer in advance: it's a programming language. You use it to create software)

My workplace has offered a "Introduction to C++ for C programmers" course. The last C++ experience I had was circa 1990, with Borland's very first Turbo C++ compiler for DOS.

I must say I fell in love with C++ exceptions. Vectors and maps are also very sexy.
Printer Friendly | Permalink |  | Top
Goldmund Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 10:50 AM
Response to Original message
1. I did C++ for 4-5 years before a few months ago...
...when I switched to C#. I must say it's even sexier.

But still, when 5PM rolls around, its sex appeal is gone.
Printer Friendly | Permalink |  | Top
 
MrSoundAndVision Donating Member (879 posts) Send PM | Profile | Ignore Wed Jan-14-04 11:41 AM
Response to Original message
2. Okay, if you're still there...
What's polymorphism?
Printer Friendly | Permalink |  | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 12:04 PM
Response to Reply #2
5. It's doing different things with the same statements
Like, a + b means concatenation if a and b are strings, and numeric addition if a and b are numbers.

Or, "double abs(complex num)" and "double abs(double num)" being two separately implemented functions, one of which calculates absolute value by Pythagoras and the other just reverses sign if the number is negative.

Do I get my candy? ;)
Printer Friendly | Permalink |  | Top
 
regnaD kciN Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 02:10 PM
Response to Reply #5
8. Not quite...
The example you mentioned actually refers to operator overloading, not polymorphism.

Polymorphism refers to the use of virtual functions in classes derived from a master class.

Example: You have a base class titled Class1. You derive two new classes, titled Class2 and Class3, from it. Each of the three classes has a function titled Update().

You declare an array of pointers to Class1 objects, titled pClass[]. The thing is, some of the objects whose pointers you add to the array are Class2 and Class3 objects. (Since they're derived from Class1, you can do this.) Now, you create a loop like this:

for (int x = 0; x < ARRAY_SIZE; x++)
{
pClass(x)->Update();
// those should be square brackets around the x, but the forum software won't accept it!
}

What's going to get called?

If, when creating the base class, you declare Update() as a standard function, that loop will call the Class1's Update() function for each element in the array. If, however, you declare Update() a virtual function (i.e., you implement polymorphism), when the pointer is actually to a Class2 object, it will call Class2's Update() function instead. Same with Class3. The only time Class1's Update() function will be called is when the object itself is an instance of Class1, not Class2 or Class3.

(The previous time I was looking for work, when I had less experience with C++ than I do now, the above was a question in a phone interview I had with Microsoft. I didn't get it right, and wound up not being considered for the job because of it -- therefore, I made a point of memorizing it from then on. ;-) )
Printer Friendly | Permalink |  | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 02:18 PM
Response to Reply #8
10. I thought function overloading WAS an instance of polymorphism?
Like in the abs() functions I mentioned? And virtual functions were another?

But yes, virtual functions seem to be the textbook example. (just Googled a little)
Printer Friendly | Permalink |  | Top
 
Kellanved Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 02:11 PM
Response to Reply #5
9. no candy for you
Edited on Wed Jan-14-04 02:15 PM by Kellanved
try again :evilgrin:


:hi:

Edit: as someone else spoiled it already: it is a term for Entities allowing several Types.

Printer Friendly | Permalink |  | Top
 
Kellanved Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:46 AM
Response to Original message
3. I'm still waiting for reasonable Template support
While the C++ generic programming is very cool in theory, it falls short in all compilers I've tried. Especially the error messages are about as useful as the MotD.
And the strong appeal to do something quick'ndirty is dangerous as well.

As far as cool features are concerned I like Java better; especially 1.5 looks promising.
Printer Friendly | Permalink |  | Top
 
cprise Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:58 AM
Response to Original message
4. You'll love Qt
Qt is a multiplatform framework (for GUIs and other stuff) and introduces a callback mechanism of signals and slots to C++ (this eliminates a lot of drudgery in coding).

It's free to use for non-commercial projects, otherwise there is a one-time license fee. A large number of open-source projects including KDE are based on Qt.

http://www.trolltech.com/products/qt/indepth.html
Printer Friendly | Permalink |  | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 03:07 PM
Response to Reply #4
11. I'm itching to use it
The C++ won't be used for anything GUI here, but I'll sure as hell venture into Qt. What references would you recommend for starters?
Printer Friendly | Permalink |  | Top
 
Kellanved Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 04:24 PM
Response to Reply #11
18. those
Daniel Solin : "Teach Yourself Qt-Programming in 24 Hours"; SAMS
and
Mathias K. Dalheimer: "Programing with QT"; O'Reilley
Printer Friendly | Permalink |  | Top
 
cprise Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:25 PM
Response to Reply #18
22. Qt advice from Europe. Are we surprised? :-)
No. :)

And thanks.
Printer Friendly | Permalink |  | Top
 
wtmusic Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 12:20 PM
Response to Original message
6. What kind of work do you do?
Printer Friendly | Permalink |  | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 01:29 PM
Response to Reply #6
7. Lots
- Numerous manifestations of computer programming (apps, embedded, OS, utilities, components, GUI, Web...)
- Network design/deployment
- IT teaching
- Support, administration, software maintenance
- IT consulting

etc, etc, etc. Ah, I should just say "Nerd" and be done with it. :crazy:
Printer Friendly | Permalink |  | Top
 
Ratty Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 03:14 PM
Response to Original message
12. Operator overloading
I love it.

Around here I'm an anachronism. All my colleagues are on the Java bandwagon but certain things about that language rankle my bones. I'm the lone C++ holdout. All my programs are portable, they compile and run on both Windows and Unix platforms. My java colleagues still can't seem to get that part right. Write once, run anywhere indeed! And they're always amazed at how fast my programs run. Well, duh.

Anyway, I love writing things like:

if (obj1 == obj2)

rather than being forced to do something goofy like:

if (obj1.equal(obj2))

or some such ludicrosity.

And I don't think I could live without being able to overload operators new and delete. And macros. No macros? What were they thinking????
Printer Friendly | Permalink |  | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 03:55 PM
Response to Reply #12
15. I can find no compelling reason
for not including operator overloading in Java. What was the rationale for that?
Printer Friendly | Permalink |  | Top
 
Ratty Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 04:06 PM
Response to Reply #15
16. I know the answer to this one
Edited on Wed Jan-14-04 04:16 PM by Ratty
Ivory Tower elitism. Computer Science professors who haven't coded a line in 20 years let out to design a perfect-world eutopian computer language. Seriously though, it was thought to be misleading, like many other convenient things they dumped from C++. Something like obj1.equals(obj2) makes it much clearer that a user-defined equality member is being called. With obj1 == obj2 there's no way for a user to know this isn't just the language-default equality test.

My problem with this is that it removes options. In C++ one is perfectly capable of eschewing all operator overloading and creating explicit equals() members if they so choose. In Java, this "good behavior" is forced on the programmer.

Oh yeah, add friend classes to the unfortunate list of casualties. Not something one should use often but when they make sense it sure is hard to work without them.

(Still hoping to start a good old computer language flame war here but DUers are so damn polite)
Printer Friendly | Permalink |  | Top
 
retread Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 05:14 PM
Response to Reply #16
21. Fighting over which object-oriented imperative language is "best" is
a waste of energy. There are many more similarities than there are differences.
Printer Friendly | Permalink |  | Top
 
cprise Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:30 PM
Response to Reply #16
23. The option is still there
...you just have to do more typing with an explicit method call.

Much clearer.


PS- Language flamewars mean you need I life. *I* engage in OS flamewars instead :p
Printer Friendly | Permalink |  | Top
 
Kellanved Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 04:21 PM
Response to Reply #15
17. It is only important for mathematical programs
And Java is seldomly, if ever, used for those. In normal code it is considered bad for readability etc. :shrug: IMHO a remark in the coding guidelines would have been nicer.
Printer Friendly | Permalink |  | Top
 
Ratty Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 04:29 PM
Response to Reply #17
19. Au contraire
I never do mathematical programming. Mostly I deal with XML and SGML. Good for, e.g., comparing two element objects (same element name, same set of attributes, etc.). In web programming good for comparing cookie objects. Good for comparing dates and times. Lots and lots of uses outside mathematics. True, all the textbooks seem to use the exact same example of operator overloading. It's always comparing either two matrices or two complex numbers. I've never used a matrix or a complex number in any program I have written. Still use operator overloading though.
Printer Friendly | Permalink |  | Top
 
Kellanved Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 04:49 PM
Response to Reply #19
20. well
That is considered "bad style" - and thus not part of Java (:evilgrin:). I guess the "ivory-tower" claim isn't entirely false.

I've done quite a bit mathematical programming and operator overloading is absolutely neccessary for that.
The other thing where it's IMHO important is Generic Programming - I wonder how the GP in Java 1.5 will look like.
Printer Friendly | Permalink |  | Top
 
nickgutierrez Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 03:16 PM
Response to Original message
13. Nice
I'm taking a very basic C++ class at my university. It does seem pretty complicated, but I've only been at it for a couple of weeks.
Printer Friendly | Permalink |  | Top
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 03:26 PM
Response to Reply #13
14. Some things still look like black magic to me.
Specifically, iterators. I hope to think otherwise two weeks from now. Have you got to it yet?
Printer Friendly | Permalink |  | Top
 
cprise Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:33 PM
Response to Reply #14
24. I still feel that way about them
But I am only starting to use C++ regularly.

Printer Friendly | Permalink |  | Top
 
nickgutierrez Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:34 PM
Response to Reply #14
25. No
I'm starting from scratch, having only taught myself HTML.

It's a bit more complicated :).
Printer Friendly | Permalink |  | Top
 
Endangered Specie Donating Member (1000+ posts) Send PM | Profile | Ignore Wed Jan-14-04 11:38 PM
Response to Original message
26. I took Turbo C++ 2 years in high school (way back when)...
But now in college we must do Java... TO all those C++ holdouts out there... FIGHT THE GOOD FIGHT!
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Thu Apr 25th 2024, 08:35 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC