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.
View Poll Results: Are you a C, C++, or C/C++ developer?
I use 100% C++ when I'm writing something with no target OS. When I write for *nix, though I generally have to use libc which is C, and I also try to make my library APIs C if they aren't an object libraries. I guess a more accurate way to say it is that if I want to write a "real" program that deals with files, threads, and processes then I'll make it for *nix because I don't want to determine what's POSIX and what's C89/99.
I generally program in terms of objects, so I use a lot of dynamic lists of objects and encapsulated or embedded objects, so I have to write those in C++. Most of my C++ sources in a dual project have both a C "include" header and a C++ local header.
I'll make as many sources C as possible and I greatly prefer the C I/O API to that of C++. For one, it seems like the C++ I/O system is only designed so that one has the option to avoid classic C, and also you don't have control over low-level things such as fcntl with C++. Overloaded std::ostreamoperator << are extremely useful, but ultimately impractical unless you're debugging a C++ command-line tool.
ta0kira
I prefer C++ so I can do OO with objects and inheritance - makes a lot of work I do so much easier. As do namespaces and a few other goodies. Being able to do C style i/o or C++ style i/o is particularly helpful, especially if porting C code to C++. Partial ports or mixed C/C++ programming using extern "C" { .. } is a good thing as well.
However, I stay away from some C++ language "features" such as templates. I need to do both C and C++, plus php, python, xhtml. css, javascript and a bunch more, and could do without cluttering up my brain any more than necessary.
I love C but avoid C++ like plague. I stick with Java for OO programming.
I don't know that I've ever heard it put that way before. Most people who use C choose C++ over Java as far as I can tell (to include me.) You really lose a lot of functionality with OO in Java because:
Single-inheritance only
No non-abstract members allowed in abstract classes
No virtual inheritance
No direct interface with C
(Again with no evidence) it seems to me that the Java->C++ barrier tends to be the complexity of memory management in C++ or maybe just the simplicity of GUIs in Java. Since you're a C user, does that mean the GUI does it for you?
ta0kira
Mixture of both. Probably something like C with classes.
I love the C++ language features (especially templates, inheritance etc.) but can easily live without stuff like e.g. the iostreams or static_cast (or even STL) which seem to me very convoluted (they have their purpose of course, but it seems only to those people who need the extra safety belt).
I learnt C++ and haven't really bothered learning C as there's no need for me to. I don't usually use classes, but I make use of STL stuff (vectors, for example).
I'm curious: What do you use it for? I never have.
Normally if a class inherits a base class more than once it will contain that many independent copies of it. Virtual inheritance merges those copies into one:
Code:
+--> class middle1 --+
class base1 --| |--> class final1
+--> class middle2 --+
final1 will only have one copy of base1 if middle(1|2) use virtual inheritance, whereas it would have 2 if one or both didn't. This helps in 2 ways:
Allows e.g. class dog to be created from class mammal and class domestic, both of which inherit class animal individually.
Allows abstract functions to be defined by other classes that are inherited:
Code:
struct abstract
{
virtual void function() = 0;
};
class defines_abstract : virtual public abstract
{
void function() { }
};
struct uses_abstract : virtual public abstract
{
inline void something()
{ this->function(); }
};
class steals_abstract : public uses_abstract, public defines_abstract
{
//no definition of 'function' needed
};
int main()
{
steals_abstract abstractness;
abstractness.something();
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.