473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error C2768 Illegal use of explicit template arguments

The following error arises when I try to compile [url=http://sourceforge.net/projects/tinybind/]tinybind, an apparently unsupported code project. (A compile-killing bug reported a year ago has gone unanswered.) So I'm looking for help outside.

Apparently VC2003 introduced this error, C2768, and VC2005 made matters worse. Anyway, here's the template definition:
Expand|Select|Wrap|Line Numbers
  1. template<class T>
  2. TiXmlBinding<T> const *
  3. GetTiXmlBinding( T const &, IdentityBase  );
  4.  
Here's a target class:
Expand|Select|Wrap|Line Numbers
  1. struct MyData
  2. {
  3.   int i;
  4.   double d;
  5.   char const * s;
  6.   std::vector<int> vec;
  7.   int iref;
  8.  
  9.   void setIntvalue( int in ) {
  10.     i = in;
  11.   }
  12.   int intvalue() {
  13.     return i;
  14.   }
  15.  
  16.   int & getIRef() {
  17.     return iref;
  18.   }
  19. };
  20.  
And here's the template instantiation that gets the C2768 error, just before the function body:
Expand|Select|Wrap|Line Numbers
  1. TiXmlBinding<MyData> const *
  2. GetTiXmlBinding<MyData>( MyData const &, Identity<MyData> )
  3. {
  4.   static MemberTiXmlBinding<MyData> binding;
  5.   if( binding.empty() ) {
  6.     binding.AddMember( "ITAG", Member(&MyData::i) );
  7.     binding.AddMember( "ITAGGETSET", Member(&MyData::intvalue, &MyData::setIntvalue) );
  8.     binding.AddMember( "DTAG", Member(&MyData::d) );
  9.     binding.AddMember( "STAG", Member(&MyData::s) );
  10.     binding.AddMember( "VEC", Member(&MyData::vec) );
  11.     binding.AddMember( "IREF", Member(&MyData::getIRef) );
  12.   }
  13.   return &binding;
  14. }
Anybody understand the complaint and how it might be mended? Microsoft's doc says put "template <>" in front of the function definition; that helps in some cases but not this one.

(I'm not showing you the lengthy MemberTiXmlBinding class, because it seems pretty clear this is an issue of the function header, not its body. Right?)
Apr 22 '07 #1
1 8890
weaknessforcats
9,208 Expert Mod 8TB
This code:
template<class T>
TiXmlBinding<T> const *
GetTiXmlBinding( T const &, IdentityBase );
looks odd.

Like where's the function??

You do not use function prototypes wioth templates. The template is like a macro. The compiler makes a copy of it (called a specialization), changes the placeholders (T) to your type and then calls the function.

I expected something like:

Expand|Select|Wrap|Line Numbers
  1. template<class T>
  2. TiXmlBinding<T> const *
  3. GetTiXmlBinding( T const &, IdentityBase  )
  4. {
  5.     //TODO: Put function body here
  6. }
  7.  
Apr 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: pminkov | last post by:
class A { public: template<class T> void f(); }; template<class T> void A::f<T>() { } When this code is compiled, the following error is produced: error C2768: 'A::f' : illegal use of...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
1
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following:...
3
by: stain | last post by:
hi, the following code produces an "illegal explicit template specialization" warning. I have been fiddling around a while to find a solution to specialize a template method of a specialized...
5
by: Avner | last post by:
Hi, I am creating a template library for a template class with two template arguments. Is there a way to span a suite of explicit instantiation, instead of having to specify all the...
1
by: petschy | last post by:
hello, i've run into an error when qualifying a copy ctor 'explicit'. the strange thing is that i get a compiler error only if the class is a template and declare the variable as X<Zx = y....
2
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template...
1
by: James Daughtry | last post by:
It seems impossible to explicitly specify template arguments for an overloaded operator() without giving the full name. I'd like to know where in the C++ standard this behavior is defined. I can't...
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.