473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to hide a template specialization by inheriting.

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
10 3137
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
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
* 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
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
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
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
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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
2
by: SainTiss | last post by:
Hi, If you've got a template class with lots of methods, and then you've got a type which works with the template, except for one method... What you need to do there is specialize the...
8
by: Agent Mulder | last post by:
Hi group, I have a problem with partial template specialization. In the code below I have a template struct Music with one method, play(), and three kinds of music, Jazz, Funk and Bach. When I...
4
by: Eric | last post by:
Does anyone know if you can specialize a template function for arguments that are pointers to a particular base class and not lose the subclass type? example: template <class E> void...
6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
0
by: Renzr | last post by:
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...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
6
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.