LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2005, 09:39 AM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
C and c++ confusion.. maybe stupid question.


I have been programming for a while now, primarily perl, java and Bash scriting. but I did take 2 classes on c++ last year, I just di not use it much (at all) after the class because of a large java project. and continuing school.

Now I am trying to start a project in c++, I remember enough that a few quick skims of the book allowed me to write a few warm up programs in c++, make an object, etc.

Now I need to learn threads and gui for my project so I started a few thread tutorials that explain posix threads, and also tried the gtk 2.0 tutorial on the gtk site.

the problem:

I thaught C++ was C with some extra's, I figured all C code would work in C++. In short I know c++ and use .cpp extensions on my code files, now this might be an obvious result to others, but to me it was suprising, the tutorials said to name the files .c, when I named them .cpp they fail to compile, they worked as .c though. so now my question is where do I go from here, my project is very object oriented, I need objects and thus I need c++ but all the tutorials are in C and they don't seem to be as compatible as I thaught.

Does anyone have a link to a document that explains how to do what I need, what the subtle differences between c and c++ are, or if I am totally in the wrong boat here as far as approaching this. Should I be looking for Thread and GTK tutorials that use c++?
 
Old 06-03-2005, 10:28 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
The differences between C and C++ aren't exactly trivial or subtle.

Think of them as two entirely separate languages.

Many C files will compile just fine with a C++ compiler, C++ files will never compile with a straight C compiler.

What your going to want to do is build (or use somebody else's) thread class in C++. You will have to use the same posix libraries that you'd use in C if you build the class from scratch (theres is no thread class to extend in libstdc++). It is quite hard to say why you can't compile your thread stuff with g++ without seeing the code first....

As far as gtk goes... that is actually a C API, NOT a C++ API. However, there are C++ bindings for gtk so you can use GTK in a C++ app.... Check out GTKMM for more info.
 
Old 06-03-2005, 10:31 AM   #3
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
thank you, I did actually find a c++ thread short tutorial, so I am good on that, also thanx for the info on gtkmm, I will check it out, on that note what c++ gui toolkit/api would you recommend for me, in the past I used java's awt, thats it for gui in my past.
 
Old 06-03-2005, 10:39 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I having done minimal stuff with gtkmm but it was a pretty nice way to do Gnome look and feel apps under Linux.

I perfer Qt which is a very OO, C++, gui toolkit and happens to also be the basis for KDE. Some people don't like using it for philisophical reasons however, because it is GPL'd and not LGPL'd which means if you want to create a commerical, closed source, piece of software with it you have to pay Trolltech for a special license (otherwise your forced to open source your program).
 
Old 06-03-2005, 10:42 AM   #5
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
Thank you, this has been very informative. QT never appealed to me in the past, I am not a huge fan of the feel of kde based programs, too bubbled like XP (maybe programmer preferences?) but gtkmm sounds like what I need.
 
Old 06-03-2005, 12:21 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I do tend to agree, a lot of the KDE themes are horrendous I typically use things with flat buttons and such.. but the real reason I use Qt is because it is also a cross-platform toolkit that allows you to write applications (including gui, file I/O, and networking) that work with Windows and Linux.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stupid, stupid question; I lost Klaptop. :( Surfrider Slackware 2 08-31-2005 09:12 PM
probably a stupid question mrchaos Slackware 11 04-22-2005 05:59 PM
Stupid Dumb Stupid Question... drigz Linux - Software 3 09-23-2004 03:09 PM
A very stupid question stephenk Linux - Hardware 2 08-13-2003 10:15 PM
Stupid question Citizen Bleys Linux - General 2 02-11-2002 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration