Argument domniemany funkcji.

0

Witam mam taką funkcje gdzie chce użyć argumentu domniemanego,bo czasami jak będę dodawał nowy element do listy to chce żeby tam był NULL i tak jest praktycznie zawsze,ale potem używam tej funkcji i potrzebuje czasem użyć już innej wartości i to wygląda tak:

 void dodsortcd(cd*&head, string title,song*head1=NULL)
{
	if (head == NULL)
	{
		head = new cd; 
		head->name = title;
		head->next = NULL;
		head->first = head1;
	}
	else if (head->name > title)
	{
		cd*temp = head;
		head = new cd;
		head->name = title;
		head->next = temp;
		head->first = head1;
	}
	else
	{
		cd*temp = NULL;
		cd*prev = NULL;
		cd*iterator = head;
		while ((iterator->next != NULL) && (iterator->next->name < title))
		{
			prev = iterator;
			iterator = iterator->next;

		}
		if (iterator->next == NULL)
		{
			iterator->next = new cd;
			iterator->next->name = title;
			iterator->next->next = NULL;
			iterator->next->first = head1;
		}
		else
		{
			temp=iterator->next;
			iterator->next = new cd;
			iterator->next->name = title;
			iterator->next->first = head1;
			iterator->next->next = temp;
		}

	}


}

I wyskakuje mi blad Severity Code File Description Project Line Suppression State
Error C2572 redefinition of default argument: parameter 1 Projekt2 365
Tak jakbym gdzieś zmieniał jego wartość a tego nigdzie nie robie tylko sie odwołuje do tej wartości,gdzie jest błąd?

2

Domyślne wartości dla argumentów powinny znajdować się tylko w jednym miejscu.

W pliku .h powinno być:

void dodsortcd(cd *&head, string title, song *head1=NULL);

Natomiast w pliku .cpp:

void dodsortcd(cd *&head, string title, song *head1)
{
 // ciało funkcji
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1