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

how to hide a template specialization by inheriting.

P: n/a
In the current project i involved, the hiding the template
specialization by inheriting is a desired goal. but my code can not be
complied correctly. I realy want someone can do me a favor. the code is
listed below:

// base.h
#ifndef BASE_H
#define BASE_H

template < class T > class Base
{
private:
T* _read;
const T* write;
};

#endif // base_h

// derived.h
#ifndef DERIVED_H
#define DERIVED_H
include "base.h"
#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp

class MT;

class Derived: public Base <MT>
{
};

#endif // derived.h

when compling the codes above with g++, the error massage is listed as
below.
error: `MT' is not a template type
I realy want someone can do me a favor

Jun 25 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Renzr wrote:
In the current project i involved, the hiding the template
specialization by inheriting is a desired goal. but my code can not be
complied correctly. I realy want someone can do me a favor. the code is
listed below:

// base.h
#ifndef BASE_H
#define BASE_H

template < class T > class Base
{
private:
T* _read;
const T* write;
};

#endif // base_h

// derived.h
#ifndef DERIVED_H
#define DERIVED_H
include "base.h"
#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp
mt or MT? class MT;

If MT, why this line?

--
Ian Collins.
Jun 25 '06 #2

P: n/a
I think it is not the problem of your use of template, maybe for you
include files MT.h .
I just type below code and compile it in vs2005, it works very well.

// base.h
#ifndef BASE_H
#define BASE_H
template < class T > class Base
{
private:
T* _read;
const T* write;
};
#endif // base_h
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
//include "base.h"
//#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp
class MT;
class Derived: public Base <MT>
{

};
#endif // derived.h

Jun 25 '06 #3

P: n/a
* Renzr:
In the current project i involved, the hiding the template
specialization by inheriting is a desired goal. but my code can not be
complied correctly. I realy want someone can do me a favor. the code is
listed below:


No, it isn't.

See the FAQ item "How do I post a question about code that doesn't work
correctly?" currently at <url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>.

Don't waste people's time by posting questions about code you don't show.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 25 '06 #4

P: n/a
scott wrote:
I think it is not the problem of your use of template, maybe for you
include files MT.h .


My?

Please reply on the correct branch and quote some context.

--
Ian Collins.
Jun 25 '06 #5

P: n/a
thanks for your suggestion, the codes blow is previously builded in
vs.net and can be compiled very well in the vs.net. but when it is
compiled in g+ , the error message appears as blow.
scott wrote:
I think it is not the problem of your use of template, maybe for you
include files MT.h .
I just type below code and compile it in vs2005, it works very well.

// base.h
#ifndef BASE_H
#define BASE_H
template < class T > class Base
{
private:
T* _read;
const T* write;
};
#endif // base_h
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
//include "base.h"
//#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp
class MT;
class Derived: public Base <MT>
{

};
#endif // derived.h


Jun 25 '06 #6

P: n/a
thanks for your suggestion, the codes blow is previously builded in
vs.net and can be compiled very well in the vs.net. but when it is
compiled in g+ , the error message appears as blow.
scott wrote:
I think it is not the problem of your use of template, maybe for you
include files MT.h .
I just type below code and compile it in vs2005, it works very well.

// base.h
#ifndef BASE_H
#define BASE_H
template < class T > class Base
{
private:
T* _read;
const T* write;
};
#endif // base_h
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
//include "base.h"
//#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp
class MT;
class Derived: public Base <MT>
{

};
#endif // derived.h


Jun 25 '06 #7

P: n/a
sorry, Ian Colins, the MT is right..:)
Ian Collins wrote:
Renzr wrote:
In the current project i involved, the hiding the template
specialization by inheriting is a desired goal. but my code can not be
complied correctly. I realy want someone can do me a favor. the code is
listed below:

// base.h
#ifndef BASE_H
#define BASE_H

template < class T > class Base
{
private:
T* _read;
const T* write;
};

#endif // base_h

// derived.h
#ifndef DERIVED_H
#define DERIVED_H
include "base.h"
#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp

mt or MT?
class MT;

If MT, why this line?

--
Ian Collins.


Jun 25 '06 #8

P: n/a
sorry, Ian Colins, the MT is right..:)
Ian Collins wrote:
Renzr wrote:
In the current project i involved, the hiding the template
specialization by inheriting is a desired goal. but my code can not be
complied correctly. I realy want someone can do me a favor. the code is
listed below:

// base.h
#ifndef BASE_H
#define BASE_H

template < class T > class Base
{
private:
T* _read;
const T* write;
};

#endif // base_h

// derived.h
#ifndef DERIVED_H
#define DERIVED_H
include "base.h"
#include "mt.h"
// class mt is defined in mt.h and implemented in mt.cpp

mt or MT?
class MT;

If MT, why this line?

--
Ian Collins.


Jun 25 '06 #9

P: n/a
Renzr wrote:
thanks for your suggestion, the codes blow is previously builded in
vs.net and can be compiled very well in the vs.net. but when it is
compiled in g+ , the error message appears as blow.


Please don't top post. Also your posting are appearing twice.

There isn't anything wrong with the code you have posted, there must be
something wrong in your "mt.h" file.

--
Ian Collins.
Jun 25 '06 #10

P: n/a
> Please don't top post. Also your posting are appearing twice.

There isn't anything wrong with the code you have posted, there must be
something wrong in your "mt.h" file.

--
Ian Collins.

sorry ! :)

Jun 25 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.