class DD : public class ST {} ; class ST {}; This violates a prome rule of inheritance: Never derive from concrete classes. (See Scott Meyer More Effective C++ pp 258-270). You need DD to derive from an ABC aand ST to derive from the same ABC. That way you create a DD or an ST but use it as an ... |
Przemyslaw Koprowski Hi, I have the following problem. Consider two simple classes AA and BB, BB inherits from AA. AA contains a class A inside and a pure virtual method getA returning an object of class A. BB overrides both. Here is the code: class AA { public: class A { public: A(void) {}; }; virtual A getA(void) = 0; virtual ... |
Constructors are not inherited, they can't be because a constructor is is how to construct a specific class. As soon as you sub-class from a class you get a new constructor because it is a new class with a different name. The sub-class constructor calls the base class constructor, the default one if a different one is not explicitly named. This ... |
Here is my code: #include template class RawPtr { protected: T* pointee_; public: RawPtr() : pointee_(0) {} RawPtr(T* pT) : pointee_(pT) {} }; template class SmartPtr : public RawPtr { public: SmartPtr() : RawPtr() {} explicit SmartPtr(T* pT) : RawPtr(pT) { if (pointee_ != 0) { std::cout << "SmartPtr(T* pT): pointee_ non-null." << std::endl; } } }; int ... |
Hi, I am having trouble compiling the simple code below... //leader.hpp #ifndef LEADER_HPP #define LEADER_HPP class leader { public: leader(){} virtual ~leader(){} virtual void hahaha()=0; virtual void hahahaha()=0; }; #endif //soldier.hpp #ifndef SOLDIER_HPP #define SOLDIER_HPP #include "leader.hpp" template class soldier : public leader { public: soldier(){} virtual ~soldier(){} virtual void hahaha(); virtual void hahahaha(); }; #endif //soldier.cpp #include "soldier.hpp" ... |
Sorry if this is an obvious question, but I try to let a template class inherit another template class. The code here under is a simplification of how I try to do that, but the compiler complains that 'c' in line '30 ' wasn't declared. " (g++) test.h: In member function T Test2::give(): test.h:30: error: c was not declared in this ... |
Hi, I'm having problems with the following code: template::access_i() definition. Of course, when I use void access_i() { A::i; } everything's OK, but I don't see why I need to ... |
|
inheritance is inheriting some of let's say a class's members,to use them in another class.. while a template is a very useful method, that allow some functions to work with more than one variable type.. like int, char, float or even objects...etc with templates you don't declare a certain variable as a parameter or a return value, you just make it ... |
|
JosephLee /* Below you will find the declaration and the definition of the class Format that can be used to manipulate the ostream. Although the class is only capable of setting the width and precision, further functionality could be added. The class is implemented as a template class. Your task is to rewrite it for two types (int and double) without ... |
On May 26, 5:44 pm, Gaijinco template class List { // something here > }; > and another class > class Contact { // something here > }; > What makes more sense: > class Agenda : public List { > }; > or should I inherit from the template ... |
I have a prbl. cannot seem to compile this simple code: (might this be a bug?) gcc version 4.1.2 //Begin code template class FirstClass{ public: T a; }; template class SecondClass : public FirstClass{ public: T func(){return a;} }; int main(){} //End Code Compiler test.cpp: In member function T SecondClass::func(): test.cpp:10: error: a was not declared in ... |
Hello, I'm not new to C++, but for some reason, until now I'd never had a need for deriving templated classes. Now though, I find myself seeing a weird problem. If I have a templated base class (Base), and a template derived class (Derived, which is publicly inherited from Base with the same template parameters), why must I prefix all "Base" ... |
RThaden@web.de Hi all, I looked in several books, articles, etc. but did not find a solution to my problem. Maybe somebody out there can help a desperate, not toooo experienced programmer: I want to represent functional blocks by lists of parameters. Lets say, functional blocks represent different algorithms which, of course, have very different parameters. Thus, a functional block contains lists ... |
Although it is really confusing behaviour between two versions of g++, I know a workaround for this. Just qualifying the member with its class name avoids the compilation error. May be some expert can give an explanation and better solution. The following will compile without error. template class A { public: C c; double a; }; template class B ... |
Hello group, I have a problem with template classes and inheritance. I've searched on the internet to find a solution but all the examples look the same as my code (as far as I can tell) and I can't find my mistake (maybe there's something wrong with my eyes). I've two classes: template< class T > class ITestTemplateA { public: ITestTemplateA() ... |
hi, all Suppose I have a template class A template |
tirzanello@gmail.com Hi guys, I'm becoming crazy with templates, maybe for it's a trivial problem... but I can't go through :-( any hint will be appreciated. I show you without templates a piece of code: 2 classes, one inherited by the other, like these: #include using namespace std; class A { public: A () {a=100; b=50;}; virtual void f()=0; void g() ... |
I am trying to figure out if this will work. I have a template base class that I want to be able to inherit from, the classes that will need to inherit from this also need to be tamplates. Is this possible or do i need to think of another way to do it? |
Hi. I have a problem with a template class that I'm trying to inherit from. The code for the base class is: template class BaseClass { public: BaseClass(); ~BaseClass(); UINT getSize(); BOOL exists(UINT pos); VOID swap(UINT nFirst, UINT nSecond); VOID remove(UINT pos); protected: T* _head; UINT _size; virtual T* getNode(UINT pos); }; I then inherit this class: class AnotherClass: ... |
I have just come across the following fact. Names defined in a template superclass of the current template must be qualified as being from the superclass. Alternatively, you can also qualify those names by preceding them with this->. An example might be clearer to read: template struct Base { int m; }; template struct Derived : public ... |
A VC++ Version that works as promised Code: #include #include "stdafx.h" #include template class Rectangle { protected: T Width; T Length; T Area; public: Rectangle(){Width = (T)0;Length = (T)0;Area = (T)0;} ; Rectangle(T Wid, T Len){ Width = Wid; Length = Len; Area = Width * Length;}; T GetArea(){ return Area; }; T GetLength(){ return Length; }; ... |