Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this is the "testlist"function which is in "server.cpp"file.
C++
#include "stdafx.h"
#include "WinSock2Server.h"
//YLN added 2010-09-25
#include <iostream>
#include <string>
using namespace std;
#include "router.h"

// Ended
//YLN added 2010-09-25
template <typename T>
void testList(Router < T > &listObject, const string &typeName)
{
    cout <<" Testing a list of " << typeName << " values \n";
	instructions ();
	int choice;
	T value;
	do
	{
      cout << "?";
	  cin >> choice;
	  switch (choice)
	  {
	  case 1:
		  cout << "enter" << typeName <<":";
		  cin >> value;
		  listObject.Register(value);
		  listObject.print();
		  break;
	  case 2:
	      cout << "enter" << typeName <<":";
		  cin >> value;
		  listObject.sendRegistration(value);
		  listObject.print();
		  break;	 
      case 3:
	      if (listObject.sendRegistrationCancellation(value))
			  cout << value <<" removed from list\n";
		  listObject.print();
		  break;	 

	  case 4:
	      if (listObject.sendCancellationConfirmation(value))
			  cout << value <<" removed from list\n";
		  listObject.print();
		  break;	 
        
	  }
	} while (choice != 5);
	cout << "End list test \n\n";
}
void instructions ()
{
	cout << "enter one of the following:\n"
		<< " 1 to register node to the list\n"
		<< " 2 to sendRegistration to the node \n"
		<<" 3 to sendRegistrationCancellation to the list\n"
		<<"4 to end list processing \n";
}
	//Ended
int _tmain(int argc, _TCHAR* argv[])
{
	        Router <int > integerRouter;
			testList ( integerRouter, "integer");
			Router < double > doubleRouter;
			testList ( doubleRouter, "double");
	WinSock2Server *srv = new WinSock2Server();
	srv->STEP1_InitializeWinsock();
	srv->STEP2_CreateAndBindSocket();
	srv->STEP3_ListenOnSocket();
	srv->STEP4_AcceptingConnection();
	srv->STEP6_Disconnect();	
	 //
	
	return 0;
}

Got errors as:
1>c:\documents and settings\lina\desktop\winsock2-basicclientserver1\winsock2-basicclientserver\winsock2server\server\winsock2server.cpp(134) : error C3861: 'testList': identifier not found
1>c:\documents and settings\lina\desktop\winsock2-basicclientserver1\winsock2-basicclientserver\winsock2server\server\winsock2server.cpp(137) : error C3861: 'testList': identifier not found



According to the errors displayed, the compiler does not recognise it, but i donot know how to make it recognise.
Posted
Updated 3-Oct-10 1:31am
v2
Comments
Richard MacCutchan 3-Oct-10 8:42am    
I'm no expert in templates, but I have a feeling you may need a semi-colon (;) after your template definition(s).

Just for the record, the following shortened form of your code compiles successfully:
C++
using namespace std;

template <typename T>
struct Router
{
    T rval;
};
// Ended
//YLN added 2010-09-25
template <typename T>
void testList(Router < T > &listObject, const string &typeName)
{
    cout <<" Testing a list of " << typeName << " values \n";
    cout << "End list test \n\n";
};
//Ended
int _tmain()
{
//  int integerRouter;
            Router <int > integerRouter;
            testList ( integerRouter, "integer");
            Router < double > doubleRouter;
            testList ( doubleRouter, "double");
    return 0;
}
 
Share this answer
 
Check if the following work -
testList<int>(integerRouter, "integer");
testList<double>(doubleRouter, "double");
 
Share this answer
 
linayang wrote:
this is the "testlist"function which is in "server.cpp"file.


Why isn't it in an include file? Unless you're using a compiler based on EDG you can't export a template definition from a source file and just include the prototype somewhere. Whatever calls testlist needs to see it's full definition - in your case it needs to be introduced into winsock2server.cpp, either by including it or wholesale cut-and-paste.

Cheers,

Ash

PS: Actually, while I'm on the subject...

The router definition needs to be visible to whatever you're compiling testList in as well.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900