Sign in to follow this  
kknd2006

stl container as function's parameter

Recommended Posts

hello everyone! i found a error C2061 when i try to use a list as a parameter of a function The code like the following In NPC.h #include <list> #include <functional> #include <algorithm> class NPC { //data... //function bool Search(list<NPC*>& npc); } At c++ primer 3rd edition, it show that we can use container as a function's paramter it's code like that void putValues(const vector<int>&){..} On the msdn, it claim that " template <class T, typename T::type (*pFunc)() > void MyFunction(); When you use template parameter as a type, you must use the typename keyword. According to ANSI C++ standards, a qualified name that refers to a type type specifier and that depends on a template parameter must be prefixed by the typename keyword." How can i solve this problem?! should i change the input function parameter to other data type!?

Share this post


Link to post
Share on other sites
Quote:
Original post by kknd2006
hello everyone!
i found a error C2061 when i try to use a list as a parameter of a function
The code like the following

In NPC.h
#include <list>
#include <functional>
#include <algorithm>
class NPC
{
//data...

//function
bool Search(list<NPC*>& npc);
}

list is in namespace std, so it should be:
bool Search(std::list<NPC*>& npc);

Share this post


Link to post
Share on other sites
Quote:
Original post by kknd2006
On the msdn, it claim that
"
template <class T, typename T::type (*pFunc)() >
void MyFunction();

When you use template parameter as a type, you must use the typename keyword. According to ANSI C++ standards, a qualified name that refers to a type type specifier and that depends on a template parameter must be prefixed by the typename keyword."


The typename keyword only needs to be used when you have a nested type specifier using a template parameter. In the msdn example, type is a member of the type T, which is a template paremeter. Your function parameter only needs the typename keyword if it fits this case, since it's just like any other variable declaration.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this