Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

c++ templated methods

Name: Anonymous 2007-10-07 1:33

How to write implementation of method foo?


template <class T>
class Foo
{
public:
    Foo(void){}
    ~Foo(void){}
    template<class T1> void test(T1 a);
};

Name: Anonymous 2007-10-07 1:33

method test sorry, not foo.

Name: Anonymous 2007-10-07 1:58

Bump

Name: Anonymous 2007-10-07 2:22

what is a timplate lol?

Name: Anonymous 2007-10-07 2:23

Name: Anonymous 2007-10-07 2:43

>>4
A c++ template is a way to achieve generalization amongst classes and functions, by removing specification of a specific type. A good example is a container class which holds instances of some object T, where T is the type of the object like int, char, or a user defined type.

Name: Anonymous 2007-10-07 2:44

>>4
You can think of it like Haskell type classes, if that helps.

Name: Anonymous 2007-10-07 4:05

>>7
That is an insult to Haskell.

Name: Anonymous 2007-10-07 4:21

>>1
#include <iostream>

template < class T >
struct Foo {
        template < class T1 >
        void bar( T1 arg );
};

template < class T >
template < class T1 >
void Foo<T>::bar( T1 arg ) {
        std::cout << arg << std::endl;
}

int main( int argc, char* argv[] ) {
        Foo< int > foo;
        foo.bar( "y halo thar" );

        return 0;
}

Name: Anonymous 2007-10-07 8:20

>>9
Ah, thank you. I tried doing
template<class T, class T1> thinking that would work, it didn't. Rather unfortunant syntax I think

Name: Anonymous 2007-10-07 8:29

C++ sure looks confusing

Name: Anonymous 2007-10-07 8:36

>>10
A surprise awaits you:

Put this code into .h file:
template < class T >
struct Foo {
        template < class T1 >
        void bar( T1 arg );
};

,and this code into .cpp file:
template < class T >
template < class T1 >
void Foo<T>::bar( T1 arg ) {
        std::cout << arg << std::endl;
}


And it's not going to work! With templates you can't have separate compilation. Hooray for c++! (and export isn't implemented anywhere so shut up, stroustrup)

Name: Anonymous 2007-10-07 14:22

C++ is generically impaired.

Name: Anonymous 2007-10-07 14:26

>>13
lol!

Name: Anonymous 2007-10-07 14:33

L.O.L. SEPPLES

Name: Anonymous 2007-10-07 16:25

>>15
better than lisp

Name: Anonymous 2007-10-07 16:50

>>12
#include file.cpp
?

Name: Anonymous 2007-10-07 17:23

>>16
Lol templates and macros are Church-Touring equivalent.

Name: Anonymous 2007-10-07 17:37

>>17
That's just plain silly. Use an extension which doesn't indicate a separate compilation unit (ie, *.h or *.inc).

>>12
Arguably, C++'s whole template system is pretty retarded, but at the same time they're complex enough to let you hack around quite a few other limitations of C++. See also: compile-time fizzbuzz.

Name: Anonymous 2011-01-31 20:35

<-- check em dubz

Name: Anonymous 2011-02-03 4:31

Don't change these.
Name: Email:
Entire Thread Thread List