error C2679: binary '>>' : no operator found

The full error message reads: Error C2679: binary ‘<<‘ : no operator found which takes a right-hand operand of type ‘Ar<int>’ (or there is no acceptable conversion) How can I fix it? #include <iostream> using namespace std; template<class T> class Dun { private: T* array{ nullptr }; public: Dun(T* _array) : array(_array) {} T& Get(int… Read More error C2679: binary '>>' : no operator found

How do I declare the root as global and set it to null to indicate an empty tree in a structure in c++?

As a beginner in c++, I have encountered a problem trying to implement a structure for binary search tree. Shown below is part of my code but c++ kept reminding me that the "data member initializer is not allowed". #include<iostream> using namespace std; struct BstNode{int key; BstNode*Left; BstNode*Right; BstNode*root = NULL;}; >Solution : You simply… Read More How do I declare the root as global and set it to null to indicate an empty tree in a structure in c++?

indexing an element from a volatile struct doesn't work in C++

I have this code: typedef struct { int test; } SensorData_t; volatile SensorData_t sensorData[10]; SensorData_t getNextSensorData(int i) { SensorData_t data = sensorData[i]; return data; } int main(int argc, char** argv) { } It compiles with gcc version 8.3, but not with g++. Error message: main.c: In function ‘SensorData_t getNextSensorData(int)’: main.c:8:34: error: no matching function for… Read More indexing an element from a volatile struct doesn't work in C++

Counter for unique types where instances are independent from each other

I am attempting to create a counter for each unique template argument that the counter receives. For example, I pass an int. The counter returns zero. I pass a float. The counter returns one. I pass an int again. The counter returns zero. Essentially, it generates a unique integer for each templated type. struct Counter… Read More Counter for unique types where instances are independent from each other

Exactly how are parameters initialized by the arguments passed in the function call in C++?

In the following code : #include<iostream> using namespace std; void fun(T1 x, T2 y, T3 z){ // some code } int main(){ T1 a; T2 b; T3 c; fun(a,b,c); } I wanted to understand, how the parameters(x, y, and z) in the function "fun" are getting initialized by the arguments(a,b, and c) passed during the… Read More Exactly how are parameters initialized by the arguments passed in the function call in C++?

How to make data from a text file be filtered into a vector

I have a little program I don’t know how to make. Basically, it is a function to create a vector with data from a text file that meets a parameter in its text. text_in_vector("file.txt", "10") text example: Karen10, Lili12, Stacy13, Mack10 vector results {"Karen10","Mack10"} >Solution : Try something like this: #include <fstream> #include <vector> #include… Read More How to make data from a text file be filtered into a vector

Why removing random element from vector and list costs almost the same time?

As cppreference says Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions. Considering the continuous memory used by std::vector where erase should be linear time. So it is reasonable that random erase operations on std::list should be more efficient than std::vector. But I… Read More Why removing random element from vector and list costs almost the same time?