template specialization compile error

N

Naveen

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 -----------------------
 
S

Sharad Kala

Naveen said:
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 said:
}
};

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top