Template problem no. 2

Discussion in 'C++' started by Espen Ruud Schultz, Jul 19, 2003.

  1. ( This might get posted twice, because I posted with a subject another topic
    already had, so the first post got lost in it. What is up with this? Is it
    the news protocol or Outlook Express? )

    Anybody care to explain why the below code doesn't work?

    TIA!

    , Espen


    #include <iostream>
    class TypeTXT {
    public:
    TypeTXT( void ) { std::cout << " TypeTXT" << std::endl; }
    ~TypeTXT( void ) { std::cout << "~TypeTXT" << std::endl; }
    };
    class TypeBMP {
    public:
    TypeBMP( void ) { std::cout << " TypeBMP" << std::endl; }
    ~TypeBMP( void ) { std::cout << "~TypeBMP" << std::endl; }
    };
    template< class Object > DataObject {
    public:
    DataObject( void ) { std::cout << " DataObject" << std::endl; }
    ~DataObject( void ) { std::cout << "~DataObject" << std::endl; }
    };
    int main( void ) {
    DataObject< TypeTXT > ObjectTXT;
    DataObject< TypeBMP > ObjectBMP;
    return 0;
    }
     
    Espen Ruud Schultz, Jul 19, 2003
    #1
    1. Advertising

  2. "Espen Ruud Schultz" <> wrote in message
    news:Zm9Sa.14251$...
    | ( This might get posted twice, because I posted with a subject another topic
    | already had, so the first post got lost in it. What is up with this? Is it
    | the news protocol or Outlook Express? )

    [snip]

    Be patient.

    Posts don't always arrive immediately on Usenet.

    Cheers.
    Chris Val
     
    Chris \( Val \), Jul 19, 2003
    #2
    1. Advertising

  3. Espen Ruud Schultz

    mjm Guest

    The template parameter Object doesn't show up anywhere inside the body
    of the class DataObject. Consequently it can't influence the class
    behaviour.

    Do this instead

    #include <iostream>
    class TypeTXT {
    public:
    TypeTXT( void ) { std::cout << " TypeTXT" << std::endl; }
    ~TypeTXT( void ) { std::cout << "~TypeTXT" << std::endl; }
    };
    class TypeBMP {
    public:
    TypeBMP( void ) { std::cout << " TypeBMP" << std::endl; }
    ~TypeBMP( void ) { std::cout << "~TypeBMP" << std::endl; }
    };
    template< class Object > DataObject {
    public:
    DataObject( void ) { Object(); }
    ~DataObject( void ) { ~Object(); }
    };




    "Espen Ruud Schultz" <> wrote in message news:<Zm9Sa.14251$>...
    > ( This might get posted twice, because I posted with a subject another topic
    > already had, so the first post got lost in it. What is up with this? Is it
    > the news protocol or Outlook Express? )
    >
    > Anybody care to explain why the below code doesn't work?
    >
    > TIA!
    >
    > , Espen
    >
    >
    > #include <iostream>
    > class TypeTXT {
    > public:
    > TypeTXT( void ) { std::cout << " TypeTXT" << std::endl; }
    > ~TypeTXT( void ) { std::cout << "~TypeTXT" << std::endl; }
    > };
    > class TypeBMP {
    > public:
    > TypeBMP( void ) { std::cout << " TypeBMP" << std::endl; }
    > ~TypeBMP( void ) { std::cout << "~TypeBMP" << std::endl; }
    > };
    > template< class Object > DataObject {
    > public:
    > DataObject( void ) { std::cout << " DataObject" << std::endl; }
    > ~DataObject( void ) { std::cout << "~DataObject" << std::endl; }
    > };
    > int main( void ) {
    > DataObject< TypeTXT > ObjectTXT;
    > DataObject< TypeBMP > ObjectBMP;
    > return 0;
    > }
     
    mjm, Jul 19, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Theis
    Replies:
    2
    Views:
    477
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    538
    tom_usenet
    Jul 24, 2003
  3. Replies:
    1
    Views:
    2,113
    Gianni Mariani
    Jun 8, 2007
  4. Peng Yu
    Replies:
    3
    Views:
    781
    Thomas J. Gritzan
    Oct 26, 2008
  5. nguillot
    Replies:
    5
    Views:
    532
Loading...

Share This Page