Issue when creating a pointer class

Hello,

I created my own vector class so store data read in from a txt file. My vector class is its own, in its own namespace, and I am making a CSV reading class. If I declare my vector class with new (keyword), it kinda breaks, but not if it is created normally.

1
2
3
4
5
6
7
8
9
10
11
namespace MYVEC {
template <class T>
class myvec {

public:
  T getCurrent(void) { return *(arr + (sizeof(T) * itr)); }

  // Other stuff
private:
  int itr; // Maintains the current position in myvec, set by user
}}


When I try to allocate it in the ctor of my CSV class this does not work
1
2
3
4
5
6
7
8
9
10
//Declared in mycsv as such
MYVEC::myvec<char> *mv;

// As in the cpp file
mycsv::mycsv() {
  mv = new MYVEC::myvec<char>();
}

// If I try to use it in a class function
mv->getPosition() //Segment faults 


But if I remove the pointer, and declare it static, there is no problem. I have been trying to debug it in gdb, to no avail, any help would be appreciated.

Topic archived. No new replies allowed.