I am confused on how to implement the copy constructor, operators and a destructor given different contexts

I have a vector(int size_=0, double = 0); constructor from a given vector class and I have to implement the copy constructor: vector(const Vector&)
The copy constructor needs to make a deep copy of the
provided Vector object, and the assignment operator should release all memory controlled by the current
object before it makes a deep copy of the provided Vector object.

I also have to implement a bool operator==(const Vector &) const) and a bool operator!=(const Vector &) const; operators,These comparison operators should define how tests for equality and inequality are performed.

Salem commented: I saw nothing urgent in this post. -7

Recommended Answers

All 5 Replies

Too vague. Show where your problem is.

I have a vector(int size_=0, double = 0); constructor from a given vector class and I have to implement the copy constructor: vector(const Vector&)
The copy constructor needs to make a deep copy of the
provided Vector object, and the assignment operator should release all memory controlled by the current
object before it makes a deep copy of the provided Vector object.

I also have to implement a bool operator==(const Vector &) const) and a bool operator!=(const Vector &) const; operators,These comparison operators should define how tests for equality and inequality are performed.

I also have to implement [...]

Right, *you* have to. If you do not know where to start, say so. If you already have something that does not work, post it and somebody can tell you where you went wrong. Otherwise it looks like you are asking for someone to do your homework for you.

These links might help if you do not know where to start:
http://www.parashift.com/c++-faq-lite/ctors.html
http://www.parashift.com/c++-faq-lite/assignment-operators.html
http://www.parashift.com/c++-faq-lite/operator-overloading.html

See if this could help you. It is my string class assignment operator function.

Letters& Letters::operator =(Letters& Str1) //assignment operator
	{
		if(this == &Str1) //check for self assignment
			return *this;

		delete [] str;

		Len = Str1.Len;
		
		str = new char[Len+1];
		
		strcpy(str,Str1.str);
		
		str[Len] = NULL;

		return *this;
	}

I think this should help you somewhat. Also is your vector
class dynamic or is there some sort of limiting number, or
is it a wrapper to std::vector, or is it something your teacher provides and you don't know?

it is limited by wat ever size the vector has

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.