Hello to every body

I hope every one keep in best state.

I want to help me in solve this problem in my Sheet .

I use recurrence functions in like list.( with ADT file ) by modify the search function and adding Printing function in a Reverse Manner.

the problems is :
error LNK2005.
and fatal error LNK1169.
I searched about it .
but I think the error mode by the pointer

and warning is :
MyClass <DataType,int>:: search' : not all control paths return a value
(appear after search function )

the code :
search function

template <class TYPE, class KTYPE> 
bool List<TYPE, KTYPE> :: _search (NODE<TYPE> * node,
								   NODE<TYPE> **pPre,
								   NODE<TYPE> **pLoc, 
								   KTYPE        key)
{
//	Statements 
	if ( node-> link )
	    return false;

	node = node->link;
		if ( (node->data).key == key)
	{
		*pPre = node;
		*pLoc = node-> link ;

		return true ;
	}
		else
			_search (node->link, pPre, pLoc, key);
}

and
print Function

template<class TYPE, class KTYPE> 
void List <TYPE, KTYPE > :: ReversePrint ( NODE <TYPE> * node )
{
if ( node== NULL)  
        return ;


ReversePrint (node->link);

//cout <<( node->link)->data;
cout << node-> data;

   return ;
}

  ostream & operator << (ostream  & out , Student & Data)
{
	out << "The name is : " << Data.name << "\nThe Level is : " << Data.level<< "\nThe ID is :"<<Data.key;
	return out;
}

if you want to see any another function , tell me...

must be sent the program at most after 9 houer.

I hooooooooope help me
please;

>>MyClass <DataType,int>:: search' : not all control paths return a value
Yes, tis true. The function can terminate without returning a value. When if ( (node->data).key == key) is fales, the else statement is executed and the function terminates without returning a value.

I understand from your post.
that if the node dont has the key and not null .the function terminates without returning a value.

I mean
the search is must take 3 types
1- maybe the node is null ( in end the list )
2- found the node.
3- not found in this list and the list isn't empty .
so , taken the next node to continue the search .

these 3 cases in the search , and I solve on it .
so I make this ( else) without returning because it return to the function self ( because recurrence )


sorry If I don't understand correctly ,
thank you for help me .and the problem is rest .

LNK2005 means

The given symbol, displayed in its decorated form, was multiply defined.

You didn't post the exact error message so we can't really help you with that error.

ostream & operator << (ostream  & out , Student & Data)
{
	out << "The name is : " << Data.name << "\nThe Level is : " << Data.level<< "\nThe ID is :"<<Data.key;
	return out;
}

That error message means that the above function appears in more than one *.obj file. You put that function in a header file, then included the header file in more than one *.cpp file. Move that function from the header file into just one *.cpp file and the error will be resolved.

Immmm

I write it in one time .
but maybe I but the definition of class and implement in one file*.cpp

now , I try to divide in two files .

put the class declaration in one header file, but put the implementation code in a *.cpp file.

I change the code of search to

template <class TYPE, class KTYPE> 
bool List<TYPE, KTYPE> :: _search (NODE<TYPE> **pPre,
								   NODE<TYPE> **pLoc, 
								   KTYPE        key)
{
   if ((*pLoc) == NULL)
	    return false;
   else
		if (key == (*pLoc)->data.key)
     	    return true;

		    _search ((*pPre)->link ,(*pLoc)->link, key);
	
			return false;
}

put taken error in _search ((*pPre)->link ,(*pLoc)->link, key); I don't Know why?
I tru to put or delete * put not any answer

the error:

error C2664: 'List<TYPE,KTYPE>::_search' : cannot convert parameter 1 from 'NODE<TYPE> *' to 'NODE<TYPE> **'


and I initialize it :

NODE <TYPE>  * pPre;
	pPre = NULL;
	NODE <TYPE>  * pLoc ;
	pLoc = NULL;

befor the function calling

error C2664: 'List<TYPE,KTYPE>::_search' : cannot convert parameter 1 from 'NODE<TYPE> *' to 'NODE<TYPE> **'

I don't know what more it can tell you, if you read the error message carefully it says everything. _search needs a parameter of type NODE<TYPE>** and you are passing it NODE<TYPE>* , so either change the function signature or change the way you are calling it. what is the type of 'pPre->link' ?

this function return the location of pPre and pLoc in memory , so must the function signature keep of **.
So , must to change the way you are calling it.
but how ?

template <class  TYPE> 
	struct NODE 
	  {
	   TYPE    data;
	   NODE   *link;
	  }; 

	struct Student 
	  {
	   string name ;   
	   int level;
	   int key;
	  }; 


template <class  TYPE, class KTYPE> 
	class List  
	   {
	     private:
	       NODE<TYPE> *head;
	       NODE<TYPE> *pos;
	       NODE<TYPE> *rear;
	       int         count;
                     ....
                     .... 
                    ....
                     ....
                     ....

};

thank you to help me

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.