S
somenath
Hi All,
I am trying to define explicit specialization for the following
template but I am getting compilation error
#ifndef COUNT_H
#define COUNT_H
template <class T,int size >
int count( const T (&array)[size],T elem)
{
int i;
int count = 0;
for ( i = 0; i<size; i++)
{
if ( array == elem )
{
count +=1;
}
}
return count;
}
template<> int count< const char * ,int size > ( const char *
(&array)[size ], const char *x) { }
#endif
File count_demo.cpp
#include <iostream>
#include "count.h"
using namespace std;
int main(void)
{
return 0;
}
g++ count_demo.cpp
In file included from count_demo.cpp:2:0:
count.h:21:16: error: parse error in template argument list
count.h:21:78: error: ‘size’ was not declared in this scope
count.h:21:84: error: expected ‘)’ before ‘,’ token
count.h:21:16: error: template-id ‘count<const char*, <expression
error> >’ for ‘int count(...)’ does not match any template declaration
If I remove the special template for const char * it compiles fine but
with the special template I am getting the following error.
Please let me know what is the mistake I am doing ?
I am trying to define explicit specialization for the following
template but I am getting compilation error
#ifndef COUNT_H
#define COUNT_H
template <class T,int size >
int count( const T (&array)[size],T elem)
{
int i;
int count = 0;
for ( i = 0; i<size; i++)
{
if ( array == elem )
{
count +=1;
}
}
return count;
}
template<> int count< const char * ,int size > ( const char *
(&array)[size ], const char *x) { }
#endif
File count_demo.cpp
#include <iostream>
#include "count.h"
using namespace std;
int main(void)
{
return 0;
}
g++ count_demo.cpp
In file included from count_demo.cpp:2:0:
count.h:21:16: error: parse error in template argument list
count.h:21:78: error: ‘size’ was not declared in this scope
count.h:21:84: error: expected ‘)’ before ‘,’ token
count.h:21:16: error: template-id ‘count<const char*, <expression
error> >’ for ‘int count(...)’ does not match any template declaration
If I remove the special template for const char * it compiles fine but
with the special template I am getting the following error.
Please let me know what is the mistake I am doing ?