class-template

Template class inside class template in c++

Hello, noob here still experimenting with templates. Trying to write a message processing class template template <typename T> class MessageProcessor { //constructor, destructor defined //Code using t_ and other functions foo( void ) { //More code in a perfectly fine method } private: T *t_ }; All defined in a header file. ...

How to create a 2D array in C++ using this specific container

I'm trying to port a int a[][] from Java to C++. I'm using this class as a container ArrayRef for ints because it handles references, and the project uses it extensively. In the AbstractReader class I declared const ArrayRef<int> START_END_PATTERN_; const ArrayRef<int> MIDDLE_PATTERN_; const ArrayRef<ArrayRef<int> > L_PATTERNS_; co...

Template class + virtual function = must implement?

This code: template <typename T> struct A { T t; void DoSomething() { t.SomeFunction(); } }; struct B { }; A<B> a; is easily compiled without any complaints, as long as I never call a.DoSomething(). However, if I define DoSomething as a virtual function, I will get a compile error saying that B doesn'...

Using typedefs from a template class in a template (non-member) function

The following fails to compile (with gcc 4.2.1 on Linux, anyway): template< typename T > class Foo { public: typedef int FooType; }; void ordinary() { Foo< int >::FooType bar = 0; } template< typename T > void templated() { Foo< T >::FooType bar = T( 0 ); } int main( int argc, char **argv ) { return 0; } The problem is ...