Click here to Skip to main content
11,493,391 members (65,932 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ programming socket
this is the "testlist"function which is in "server.cpp"file.
#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 2-Oct-10 23:34pm
Edited 3-Oct-10 2:31am
v2
Comments
Richard MacCutchan at 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).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Just for the record, the following shortened form of your code compiles successfully:
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;
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check if the following work -
testList<int>(integerRouter, "integer");
testList<double>(doubleRouter, "double");
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
v3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 408
1 F-ES Sitecore 244
2 Maciej Los 241
3 CPallini 233
4 Nakul Chaudhari 225
0 Sergey Alexandrovich Kryukov 10,237
1 OriginalGriff 8,730
2 Sascha Lefèvre 3,664
3 Maciej Los 3,392
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 3 Oct 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100