Do I need a copy constructor?

#ifndef MY_MIN_PQ_H
#define MY_MIN_PQ_H

#include <iostream>
#include <vector>
using namespace std;

class my_min_pq
{
public:
	//default constructor
	my_min_pq();

	//destructor 
	~my_min_pq();

	//insert element at end of sequence, and rearrange so minimum data at the front of array
	void enqueue(int data ,int priority);

	//removes data and priority from front of vector
	bool dequeue();

	//show structure based on priority where the smallest key is the first item outputted. 
	void show_pq_structure();

private: 
	//store priority
	vector<int> pq;

	//store data
	vector<int> data;

	//finds minimum priority value in array and swap positions of this priority index 
	//with the first index as well as data values
	void find_min();

};

my_min_pq::my_min_pq()
{
	pq;
	data;
}

my_min_pq::~my_min_pq()
{
	~pq();
	~data();
}

when u write

vector<int> pq;
vector<int> data;

the constructor gets invoke which is

vector<int>::vector();

In line #41, #42, #47, #48: what do u suppose u are doing.
Thats not the way how u invoke the constructor/destructor.

U could have done something like:

#ifndef MY_MIN_PQ_H
#define MY_MIN_PQ_H

#include <iostream>
#include <vector>
using namespace std;

class my_min_pq
{
public:
	//default constructor
	my_min_pq();

	//destructor 
	~my_min_pq();

	//insert element at end of sequence, and rearrange so minimum data at the front of array
	void enqueue(int data ,int priority);

	//removes data and priority from front of vector
	bool dequeue();

	//show structure based on priority where the smallest key is the first item outputted. 
	void show_pq_structure();

private: 
	//store priority
	vector<int> *pq;

	//store data
	vector<int> *data;

	//finds minimum priority value in array and swap positions of this priority index 
	//with the first index as well as data values
	void find_min();

};

my_min_pq::my_min_pq()
{
	pq = new vector<int>();
	data = new vector<int>();
}

my_min_pq::~my_min_pq()
{
	delete pq;
	delete data;
}

thanks i completely forgot about that.

how do i do this without changing it to a pointer? then i need to change all the remainder of my code and would have to use a iterator.

how do i do this without changing it to a pointer? then i need to change all the remainder of my code and would have to use a iterator.

in that case just remove the statements in the constructor and destructor in your first approach. The constructor is automatically called when u declare the variable. And teh destructor will also be invoked when its scope is over. U dont need to worry about that.

but my teacher wants a constructor and a destructor. So i guess i have to use pointers.

but my teacher wants a constructor and a destructor. So i guess i have to use pointers.

upto u.
U can keep your constructor/destructor where u might want to do something else, or yes, u can use pointers.

actually it isn't too difficult to change my code. Thanks for help. I realized i was getting many errors because two variable are named the same thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.