C++

emplace_back vs push_back in C++

First of all, let’s start from the definition of each method: push_back: Adds a new element at the end of the container, after its current last element. The content of val is copied (or moved) to the new element. This effectively increases the container size by one, which causes an [...]

2024-04-20T19:00:22+05:30Categories: Programming|Tags: |

Commonly used GCC Compiler Flags

GNU Compiler Collection (GCC) is an optimizing compiler produced by the GNU Project supporting various programming languages, hardware architectures and operating systems. It includes front ends for C, C++, Objective-C, Fortran, Ada and Go. This article discuss about commonly encountered GCC compiler flags. Disable the unused variable warningsUse flag -Wno-unused-variable [...]

2022-02-22T18:25:20+05:30Categories: IDE|Tags: , |

Explicit Constructor in C++

explicit keyword in C++ tell the compiler that a certain constructor may not be used to implicitly cast an expression to its class type. It is an optional decoration for constructors that take exactly one argument. It only applies to single-argument constructors since those are the only constructors that can [...]

2024-05-11T17:02:19+05:30Categories: Programming|Tags: |

Calling C/C++ function from JAVA

C/C++ and Java are popular programming languages. The Java Native Interface (JNI) is a standard to integrate in a portable way C++ and Java code. JNI works both way i.e. C++ implementation can be called from JAVA and vice versa. This post discussed about calling C/C++ implementation from JAVA. native [...]

2022-02-03T19:47:41+05:30Categories: Programming|Tags: , |

Use of final Keyword in C++

final keyword specifies that a virtual function cannot be overridden in a derived class. It also specifies that a class cannot be inherited from. It ensures that the function is virtual, otherwise a compile-time error is generated. Similarly when used in a class definition, it ensures that class cannot be [...]

2021-07-30T18:05:32+05:30Categories: Programming|Tags: |

bind Function and Placeholders in C++

Function template std::bind takes a function as input and generates a forwarding call wrapper. Calling this wrapper is equivalent to invoking input function with some of its arguments. A placeholder forwards argument to the calling function object returned by std::bind. Syntax std::bind is defined in functional header. Below is syntax [...]

2020-09-25T15:25:33+05:30Categories: Programming|Tags: |

accumulate and partial_sum Function in C++

std::accumulate() computes the sum of the given elements in the range. std::partial_sum() computes the partial sums of the elements in the subranges of the range. Syntax Below is the syntax of accumulate. template <class InputIterator, class T> T accumulate (InputIterator first, InputIterator last, T init); template <class InputIterator, class T, [...]

2020-09-23T18:08:25+05:30Categories: Programming|Tags: |

copy and copy_if Function in C++

std::copy() and std::copy_if() function in C++ copies the elements in the range, to another range. However std::copy_if() function copies the element based on result of unary function passed to it. Syntax Syntax of copy() and copy_if() function is template <class InputIterator, class OutputIterator> OutputIterator copy (InputIterator first, InputIterator last, OutputIterator [...]

2020-09-23T16:51:45+05:30Categories: Programming|Tags: |

Smart Pointers in C++

Smart pointers in C++ are a wrapper class. It is used to manage dynamically allocated memory and to ensure that the memory gets deleted when the smart pointer object goes out of scope. Smart pointers are just classes that wrap the raw pointer and offer the same syntax (overloaded -> [...]

2020-09-03T19:02:46+05:30Categories: Programming|Tags: |

Difference between Pointer and Reference

A pointer in C++ is a variable that holds the memory address of another variable. A reference is an alias for an already existing variable. Once a reference is initialized to a variable, it cannot be changed to refer to another variable. Hence, a reference is similar to a const [...]

2020-09-03T15:25:29+05:30Categories: Programming|Tags: |
Go to Top