What is the meaning of ‘const’ at the end of a member function declaration?

When you add the const keyword to a method the this pointer will essentially become a pointer to const object, and you cannot therefore change any member data. (Unless you use mutable, more on that later). The const keyword is part of the functions signature which means that you can implement two similar methods, one … Read more

What is std::move(), and when should it be used and does it actually move anything?

1. “What is it?” While std::move() is technically a function – I would say it isn’t really a function. It’s sort of a converter between ways the compiler considers an expression’s value. 2. “What does it do?” The first thing to note is that std::move() doesn’t actually move anything. It changes an expression from being … Read more

Why doesn’t a derived template class have access to a base template class’ identifiers?

That’s two-phase lookup for you. Base<T>::NO_ZEROFILL (all caps identifiers are boo, except for macros, BTW) is an identifier that depends on T. Since, when the compiler first parses the template, there’s no actual type substituted for T yet, the compiler doesn’t “know” what Base<T> is. So it cannot know any identifiers you assume to be … Read more

What C++ idioms should C++ programmers use? [closed]

By far the single most important “pattern” to learn and know that’s (nearly) unique to C++ is RAII (Resource Acquisition Is Initialization). Edit: (To answer extra question edited into the question). You use RAII primarily to (semi-)automate resource management. The most obvious use is freeing resources owned by objects when the owning objects go out … Read more

How do I prevent a class from being allocated via the ‘new’ operator? (I’d like to ensure my RAII class is always allocated on the stack.)

All you need to do is declare the class’ new operator private: class X { private: // Prevent heap allocation void * operator new (size_t); void * operator new[] (size_t); void operator delete (void *); void operator delete[] (void*); // … // The rest of the implementation for X // … }; Making ‘operator new’ … Read more

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