I am very confused why my code gives error when running the valgrind memory check:
valgrind --tool=memcheck --leak-check=yes ./output
The code works perfectly when compile and run. But when running the valgrind tool it gives this message in the end.
ERROR SUMMARY: 170 errors from 9 contexts (suppressed: 2 from 2)
It would be wonderful if someone could help me out.
Thank you /Pete
#include <iostream>
#include <cstdlib>
#include <list>
#include <stdexcept>
#include <algorithm>
using namespace std;
template <typename T>
class Vector{
public:
T* p;
size_t size;
public:
Vector<T>(){
cout << "The default constructor" << endl;
this-> size = 10; // initial size
this-> p = new T[size];
}
~Vector<T>(){
cout << "The destructor" << endl;
delete [] p;
}
void print_values(){
for (unsigned i = 0; i < this->size; ++i){
std::cout << *(this->p+i) << " ";}
std::cout << endl;
}
};
int main(){
Vector <double> dvect;
//dvect.print_values(); // why gives error?
}