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.
So in Java if I don't say super() and the subclass has no parameter-less constructors, it calls a blank one?
That part of the language specification I linked tells you that if you don't start with a constructor call, the compiler will insert a call to a parameter-less constructor.
What happens if you call a parameter-less constructor that doesn't exist must be discussed elsewhere in the specification. But whatever that is, it happens the same regardless of whether you coded the call to the parameter-less constructor yourself or whether the compiler added it for you as described in 8.8.7
In C++ there are rules for whether a call to a parameter-less constructor that you haven't defined causes the compiler to generate an error message or whether it causes the compiler to invent a parameter-less constructor for you. As far as I recall, those rules are similar in Java.
If you're looking for a language that strongly encourages OO, maybe Ruby or Obj-C (as was suggested earlier). I wouldn't recommend Java, just because years of use have taught me that there is almost always a better way
I got this error compiling my C++ program. I don't understand why it says that I cannot call a base class's method.
It is pretty hard to tell you the error in your code when you didn't show us the code.
Despite that, tuxdev managed to tell you the cause of the error that is reported as line 7 of main.cpp
Looking at the messages, I can't be sure the error reported as line 8 is an unrelated error (as it appears) or a consequence of the line 7 error. Often it is best to fix errors as you understand them and then see if later errors go away or change.
If the second error remains, post the related code.
I knew about using structs instead of instance variables and functions that take the struct as a parameter instead of methods, and I like this technique, but I really need inheritance and polymorphism, too, and it is not obvious to me how you would do this as an extension of this technique.
But I wonder how i.e. GTK+ does it? it is written in pure C but still has some kind of object hierarchy.
I still don't know what -Wall, -Wextra, Weffc++, and -MD mean.
-Wall and -Wextra makes gcc complain more about stuff you might be doing wrong. It has saved me from myself on many, many occasions.
-Weffc++ produces warnings based on some of what Scott Meyer wrote about in his "Effective C++" book series. Get a copy if you don't already have one and read through it.
I actually also use -ansi -pedantic so my C++ is as standard as possible, but that's not acceptable for some stuff.
-MD makes it produce .d dependency files which are then included into the Makefile for later builds. If you don't do some kind of automated dependency tree generation, it will bite you eventually.
"LINK.o = $(LINK.cpp)" tells make to link .o files together with the C++ linker (g++) rather than the default C linker (gcc).
".PHONY = all clean" tells make that the "all" and "clean" targets don't actually refer to files and should always be considered out-of-date.
"$(wildcard src/*.cpp)" returns a list of files that match the glob src/*.cpp
"main: $(SRCS:%.cpp=%.o)" tells make that the "main" file can be built from files in the SRCS variable with their extensions changed from .cpp to .o. make already knows how to make .o files from .cpp files.
I knew about using structs instead of instance variables and functions that take the struct as a parameter instead of methods, and I like this technique, but I really need inheritance and polymorphism, too, and it is not obvious to me how you would do this as an extension of this technique.
But I wonder how i.e. GTK+ does it? it is written in pure C but still has some kind of object hierarchy.
There's really no point in debating it, but it is certainly possible, as demonstrated in this nice article. He comments that C is a non-OO language, but I think what he really means is that C doesn't force OO like some languages do. http://www.embedded.com/97/fe29712.htm
In all fairness, OO is not a one size fits all approach to coding. There are, as always, many approaches to any problem. I usually consider that it comes down to either dev time or execution time (memory, etc). The determination is usually made by the company responsible - with F/OSS projects, it often tends to be determined by the project lead.
I still see flaws with the pointer-to-superclass approach - What if you don't know the exact level of hierarchy a variable was created?
You're fundamentally assumed to know this. If you can't or don't want to keep track of it, of course the computer can help.. Hey, that's already been done and it's called "C++"!
The one thing about C++ using the same linker as C is that you *know* every feature in C++ can somehow be done in C, with various levels of pain.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.