invalid use of non-static data member

In C++, unlike (say) Java, an instance of a nested class doesn’t intrinsically belong to any instance of the enclosing class. So bar::getA doesn’t have any specific instance of foo whose a it can be returning. I’m guessing that what you want is something like: But even for this you may have to make some changes, because in versions of C++ … Read more

Javascript setInterval not working

A lot of other answers are focusing on a pattern that does work, but their explanations aren’t really very thorough as to why your current code doesn’t work. Your code, for reference: Let’s break this up into chunks. Your function funcName is fine. Note that when you call funcName (in other words, you run it) you will be alerting “test”. … Read more

Error: macro names must be identifiers using #ifdef 0

The #ifdef directive is used to check if a preprocessor symbol is defined. The standard (C11 6.4.2 Identifiers) mandates that identifiers must not start with a digit: The correct form for using the pre-processor to block out code is: You can also use: but you need to be confident that the symbols will not be inadvertently set by code … Read more

How to copy a char array in C?

You can’t directly do array2 = array1, because in this case you manipulate the addresses of the arrays (char *) and not of their inner values (char). What you, conceptually, want is to do is iterate through all the chars of your source (array1) and copy them to the destination (array2). There are several ways to … Read more