aagomez 0 Newbie Poster

I am currently having problems updating a public data member that is a vector of pointers. I have a class called node, that has a public data member called list. list is std::vector< node<T>*> and should contain pointers to other node<T> objects. I am trying to overload the assignment operator, in which case I have to reassign this->list to point to rhs.list .

Here is the complete code:

template < typename T >
class node
{

public:
	//---Constructor
	node( );
	node( const node<T> &cNode );
	node( const int &id );

	
	//---Destructor

	//---Data Members
	int id;
	std::vector< node<T>* > A;

	//---Print functions
	std::ostream& Print( std::ostream& os ) const{

		std::string outString = "{";
		for( int index = 0; index < int(this->A.size()); index++){
			std::stringstream outInt;
			outInt << this->A[index]->id;
			outString+=outInt.str();
			outString+=", ";
		}
		if(int(outString.size())>strlen(", ")){outString.resize(outString.size()-strlen(", ") );}
		outString+="}";
		return os << outString;
	};

	//---Overloaded operators
	node<T>& operator +=( node<T> *rhs );
	node<T>& operator[]( const int &index );
	node<T>& operator=( node<T> &rhs );
	
	
private:

};


template < typename T >
const node<T> operator+(const node<T> &lhs, const node<T> &rhs){
	node<T> result = node<T>(lhs);
	result += rhs;
	return result;
};

template < typename T >
std::ostream& operator<<( std::ostream &os, const node<T> &out ){
	return out.Print(os);
};


/*-------------------------------------------------------------*/

template < typename T >
node<T>::node( ){

};

template < typename T >
node<T>::node( const node<T> &cNode ){
	this->id = cNode.id;	
	this->A = cNode.A;
};

template < typename T >
node<T>::node( const int &id ){
	this->id = id;
};

//---Destructor

//---Print functions


//---Overloaded operators

template< typename T >
node<T>& node<T>::operator+=( node<T>* rhs ){
	int index = this->A.size();
	this->A.resize(index+1);
	this->A[index] = rhs;
	return *this;
};

template< typename T >
node<T>& node<T>::operator=(  node<T> &rhs ){
	this->A = node(rhs).A;
	return *this;
};

template< typename T >
node<T>& node<T>::operator[]( const int &index ){
	return *this->A[index - 1];
};
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.