Results 1 to 4 of 4

Thread: How to initialize static members in template classes

  1. #1
    Join Date
    Apr 2009
    Posts
    65

    How to initialize static members in template classes

    I have a class inherited from Class CLASSTYPE <T> classes that are templates.

    Now, inside each CLASSTYPE <T> is called a static pointer, which is initialized to NULL value, (is it possible to achieve this).

    Theoretically we could do this, to find each value, and as well to initialize the static member to NULL ...

    I tried to move the definition of header which no longer gives error when we try to create the class, but with an error could we try to use classInfo.

    Thanks

  2. #2
    Join Date
    Jan 2009
    Posts
    143

    Re: How to initialize static members in template classes

    I can't really say that it will run using the a pointer but I would speculate it because it's unable to calculate the size of the template class because we then knowns the size of the template parameter and hence the size of the class.. Making "registrar" a pointer which may solves the problem, regardless of what the template parameter might be.

  3. #3
    Join Date
    Feb 2009
    Posts
    105

    Re: How to initialize static members in template classes

    Below here I am providing you some code for the template classes,just try to run it using it.

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    template< typename T >//here you will declare your template
    class Test
    {
    public:
    temp( const exa1 & id ) : A_id(id){ }
    private:
    exa1 A_id;
    static int tecldh_count;
    };
    
    int Test< float >::s_count = 0;
    
    int main( int argv, char *argv[] )
    {
    Temp< float > temp( 1.0f );
    
    return 0;
    }

  4. #4
    Join Date
    Dec 2008
    Posts
    183

    Re: How to initialize static members in template classes

    My initial guess is that template static data member is either to initialized before the first use by any module whatever may be implemented in the program or int already initialized module (and that may be too late for using it by other external static object).

Similar Threads

  1. Listing members of Group with >1500 members
    By Umesh Thakur in forum Windows Server Help
    Replies: 11
    Last Post: 03-02-2012, 05:29 AM
  2. Replies: 2
    Last Post: 28-01-2012, 03:50 PM
  3. Display members of a group with more than 1500 members
    By Simon G in forum Windows Server Help
    Replies: 5
    Last Post: 25-10-2011, 12:35 PM
  4. Java example for static members
    By ScarFace 01 in forum Software Development
    Replies: 6
    Last Post: 05-01-2010, 05:14 AM
  5. What is static data members of class?
    By Jaiwanti in forum Software Development
    Replies: 3
    Last Post: 20-11-2009, 10:48 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,142,943.22126 seconds with 17 queries