Difference between ‘struct’ and ‘typedef struct’ in C++?

In C++, there is only a subtle difference. It’s a holdover from C, in which it makes a difference. The C language standard (C89 §3.1.2.3, C99 §6.2.3, and C11 §6.2.3) mandates separate namespaces for different categories of identifiers, including tag identifiers (for struct/union/enum) and ordinary identifiers (for typedef and other identifiers). If you just said: … Read more

How to Convert a C++ String to Uppercase

You need to put a double colon before toupper: Explanation: There are two different toupper functions: toupper in the global namespace (accessed with ::toupper), which comes from C. toupper in the std namespace (accessed with std::toupper) which has multiple overloads and thus cannot be simply referenced with a name only. You have to explicitly cast it to a specific function signature in order to … Read more

How to add element to C++ array?

There is no way to do what you say in C++ with plain arrays. The C++ solution for that is by using the STL library that gives you the std::vector. You can use a vector in this way:

“used without template parameters”

VisitedSet is a template, not a class, so you can’t use VisitedSet in a nested name specifier such as VisitedSet::getSize(). Just as you specified the declaration of class VisitedSet<T> for all class T, you must specify the definition of VisitedSet<T>::getSize() for all class T: The name of a template can, however, be used as though it were a class within a template definition: In this case, Example is short … Read more

codingbat-like site for C++

I don’t think such a site exists and I doubt it ever will. The reason is that C++ is huge – and I mean reeaallllyyy huge.When you start to write C++ code professionally (that is, 40hrs per week) and take 1 or 2 hrs for learning new stuff about C++ every day (that is, 5-10hrs per week), reading books … Read more

How to call a parent class function from derived class function?

I’ll take the risk of stating the obvious: You call the function, if it’s defined in the base class it’s automatically available in the derived class (unless it’s private). If there is a function with the same signature in the derived class you can disambiguate it by adding the base class’s name followed by two colons base_class::foo(…). … Read more

What is the use of intptr_t?

The primary reason, you cannot do bitwise operation on a void *, but you can do the same on a intptr_t. On many occassion, where you need to perform bitwise operation on an address, you can use intptr_t. However, for bitwise operations, best approach is to use the unsigned counterpart, uintptr_t. As mentioned in the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)