如何通过继承隐藏模板特化。 [英] how to hide a template specialization by inheriting.
问题描述
在我参与的当前项目中,通过继承隐藏模板
特化是一个理想的目标。但我的代码不能正确地符合
。我真的希望有人可以帮我一个忙。代码是
,如下所列:
// base.h
#ifndef BASE_H
#define BASE_H
模板< T类>班级基础
{
私人:
T * _read;
const T *写;
};
#endif // base_h
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
包括base.h
#include" mt.h"
// class mt在mt.h中定义并在mt.cpp中实现
class MT;
class派生:public Base< ; MT>
{
};
#endif // derived.h
用g ++编写上面的代码时,错误按摩列为
以下。
错误:`MT''不是模板类型
我真的希望有人能帮帮我
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
推荐答案
Renzr写道:
In我参与的当前项目,通过继承隐藏模板专业化是一个理想的目标。但是我的代码无法正确编译。我真的希望有人可以帮我一个忙。代码如下:
// base.h
#ifndef BASE_H
#define BASE_H
模板< T类>班级基地
{
私人:
T * _read;
const T *写;
};
#endif // base_h
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
includebase.h
#include" mt.h"
// class mt在mt.h中定义并在mt.cpp中实现
mt或MT? MT级;
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;
如果是MT,为什么这行?
-
Ian Collins。
If MT, why this line?
--
Ian Collins.
我认为这不是你使用模板的问题,也许对你来说
包含文件MT.h。
我只需输入下面的代码并在vs2005中编译它,它运行得很好。
// base.h
#ifndef BASE_H
#define BASE_H
模板< T类>班级基础
{
私人:
T * _read;
const T *写;
};
#endif // base_h
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
// include" base.h"
// #include" mt.h"
// class mt在mt.h中定义并在mt.cpp中实现
class MT;
class派生:public Base< MT>
{
};
#endif // derived.h
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
* 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:
不,它不是。
请参阅常见问题项目如何发布有关无法正常工作的代码的问题
?目前位于< url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>。
不要浪费人们的时间来发布关于你没有展示的代码的问题。
-
答:因为它弄乱了人们通常阅读文字的顺序。
问:为什么这么糟糕?
A:热门发布。
问:usenet和电子邮件中最烦人的事情是什么?
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?
这篇关于如何通过继承隐藏模板特化。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!