ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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++?
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.
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.
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).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.