Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Templates: "E2402 Illegal base class type"


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Nov 19, 2014 11:31 AM Last Post By: Remy Lebeau (Te...
Dmitry K

Posts: 3
Registered: 12/18/14
Templates: "E2402 Illegal base class type"  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 18, 2014 9:58 AM
Hi!

I'm using Builder XE and stuck with the

E2402 Illegal base class type: formal type 'CMCP<type,BackInit<type> >' resolves to 'CMCP<unsigned long,BackInit<type> >'

on the following template code:
template <class type>
KEY NoInit(CKeyedParam<KEY, type>& /*p*/) {
...
}
 
template <class type>
KEY ZeroInit(CKeyedParam<KEY, type>& p) {
...
}
 
template <class type>
KEY BackInit(CKeyedParam<KEY, type>& p) {
...
}
 
template<class type, KEY (*InitFunc)(CKeyedParam<KEY, type>& p) = NoInit>
class CMCP : public CCData {
....
 
template <class type>
class CMF : public CMCP<type, BackInit> {
public:
...
};


The compiler tries to resolve CMF<ULONG> in my code and fails (while CMCP<ULONG> seems to be ok). The code works perfectly in VS 2010 and GCC but I really need it to be compatible with C++ Builder.

Please, help.
Dmitry K

Posts: 3
Registered: 12/18/14
Re: Templates: "E2402 Illegal base class type"  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 5:33 AM   in response to: Dmitry K in response to: Dmitry K
Here's a generic that reproduces my case:
template <class type>
long Init0(type&) {
 
	return 0;
}
 
template <class type>
long Init1(type&) {
 
	return 1;
}
 
template <class type, long (*InitFunc)(type&) = Init0>
struct M {
	M() {InitFunc(t);}
	type t;
};
 
template <class type>
struct P : public M<type, Init1> {
};
 
M<int> m1;            // ok
M<int, Init1> m2;    // ok
P<int> p;               // E2402 

And here's a version with classes which works but looks more syntax-ugly(double type specification, etc):
template <class type>
struct Init0 {
	long init(type&) {
		return 0;
	}
};
 
template <class type>
struct Init1 {
	long init(type&) {
		return 1;
	}
};
 
template <class type, class IC=Init0<type> >
struct M {
	M() {IC i; i.init(t);}
	type t;
};
 
template <class type>
struct P : public M<type, Init1<type> > {
};
 
M<int> m1;
M<int, Init0<int> > m2;
P<int> p;                 // ok this time


How can I success with more compact function pointer version and c++ builder?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Templates: "E2402 Illegal base class type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 10:24 AM   in response to: Dmitry K in response to: Dmitry K
Dmitry wrote:

P<int> p; // E2402

What version of C++Builder are you using? In XE2, the error message is a
little more explanatory than what you showed:

E2402 Illegal base class type: formal type 'M<type,Init1<type> >' resolves
to 'M<int,Init1<type> >'

And if I try something like this:

template <class type>
struct P : public M<type, Init1<type> > {
};


Or:

template <class type>
struct P : public M<type, &Init1<type> > {
};


I get a different error:

E2336 Pointer to overloaded function 'Init1<type>' doesn't match 'long (*)(type
&)'

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Templates: "E2402 Illegal base class type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 10:50 AM   in response to: Dmitry K in response to: Dmitry K
Dmitry wrote:

P<int> p; // E2402

What version of C++Builder are you using? In XE2, the error message is a
little more explanatory than what you showed:

E2402 Illegal base class type: formal type 'M<type,Init1<type> >' resolves
to 'M<int,Init1<type> >'

And if I try something like this:

template <class type>
struct P : public M<type, Init1<type> > {
};


Or:

template <class type>
struct P : public M<type, &Init1<type> > {
};


I get a different error:

E2336 Pointer to overloaded function 'Init1<type>' doesn't match 'long (*)(type
&)'

--
Remy Lebeau (TeamB)
Dmitry K

Posts: 3
Registered: 12/18/14
Re: Templates: "E2402 Illegal base class type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 11:06 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
What version of C++Builder are you using? In XE2, the error message is a
little more explanatory than what you showed:
I'm using XE (the version was pointed in the first message and in the tags).

And if I try something like this:

template <class type>
struct P : public M<type, Init1<type> > {
};


Or:

template <class type>
struct P : public M<type, &Init1<type> > {
};


I get a different error:

E2336 Pointer to overloaded function 'Init1<type>' doesn't match 'long (*)(type
&)'
Yes, if I add <type> to the second template parameter I receive exactly the same error message that you wrote.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Templates: "E2402 Illegal base class type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 11:31 AM   in response to: Dmitry K in response to: Dmitry K
Dmitry wrote:

the version was pointed in the first message

I missed that.

and in the tags

Tags do not appear in NNTP.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02