how to hide a template specialization by inheriting.

R

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:

// 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
 
I

Ian Collins

Renzr said:
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?
 
S

scott

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
 
A

Alf P. Steinbach

* 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.
 
I

Ian Collins

scott said:
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.
 
R

Renzr

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.
 
R

Renzr

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.
 
I

Ian Collins

Renzr said:
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.
 
R

Renzr

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.


sorry ! :)
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top