Multidimensional Vectors in C++

If you are able to use C++11, multidimensional arrays and vectors of vectors can be initialized in a similar manner. However, there are differences that must be understood to access the elements without running into undefined behavior. For a multidimensional array, memory for the elements of the array is required to be allocated contiguously. For … Read more

C++ – statement cannot resolve address for overloaded function

std::endl is a function template. Normally, it’s used as an argument to the insertion operator <<. In that case, the operator<< of the stream in question will be defined as e.g. ostream& operator<< ( ostream& (*f)( ostream& ) ). The type of the argument of f is defined, so the compiler will then know the exact overload of the function. It’s comparable … Read more

variable-sized object may not be initialized c++

You can declare an array only with constant size, which can be deduced at compile time. zo1,zo2 and zoA are variables, and the values can be known only at runtime. To elaborate, when you allocate memory on the stack, the size must be known at compile time. Since the arrays are local to the method, they will be placed on the stack. You … Read more

I get this error: “glibc detected”

Even if you’re not allocating memory directly, it happens under the hood in vector code and you most likely corrupted some portion of memory by writing where you are not supposed to. The most likely reasons I can think of are: Writing to an element that is out of bounds Using a pointer/reference to an element that … Read more

Does C++11 have C#-style properties?

In C#, there is a nice syntax sugar for fields with getter and setter. Moreover, I like the auto-implemented properties which allow me to write In C++ I have to write Is there some such concept in the C++11 allowing me to have some syntax sugar on this?

Why use pointers?

I know this is a really basic question, but I’ve just started with some basic C++ programming after coding a few projects with high-level languages. Basically I have three questions: Why use pointers over normal variables? When and where should I use pointers? How do you use pointers with arrays?

C++ Returning reference to local variable

This code snippet: will not work because you’re returning an alias (a reference) to an object with a lifetime limited to the scope of the function call. That means once func1() returns, int i dies, making the reference returned from the function worthless because it now refers to an object that doesn’t exist. The second … Read more

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