By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,733 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,733 IT Pros & Developers. It's quick & easy.

template specialization compile error

P: n/a
Hello All.
I am trying to compile this code on Borland 5.6.4. The compiler is
throwing up this error message:

"main.cpp": E2299 Cannot generate template specialization from 'B<T>'
at line 12

Any help to fix this would be appreciated.

--Naveen.
// -------------------- Code Starts here ----------------------------
//
#include <iostream>

class A { };

template <typename T>
class B : public A
{
public: B() { }
};

class Testing
{
public:
template <typename T>
void load( int key, B<T>& sort = B<T>())
{
}
};

void main()
{
Testing ab;
ab.load<int>(10);
}
//
// -------------------- End of Code -----------------------
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Naveen" <ns******@gmail.com> wrote in message
Hello All.
I am trying to compile this code on Borland 5.6.4. The compiler is
throwing up this error message:

"main.cpp": E2299 Cannot generate template specialization from 'B<T>'
at line 12

Any help to fix this would be appreciated.

--Naveen.
Two errors are apparent to me.

// -------------------- Code Starts here ----------------------------
//
#include <iostream>

class A { };

template <typename T>
class B : public A
{
public: B() { }
};

class Testing
{
public:
template <typename T> void load( int key, B<T>& sort = B<T>())
ISO C++ forbids binding rvalues to non-const references. So the reference
should be to a const object.
void load( int key, const B<T>& sort = B<T>())
^^^^ { }
};

void main()
main has never ever in the history of C++ returned void. The return type is
int.
{
Testing ab;
ab.load<int>(10);
}
//


Sharad
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.