CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: template

  1. #1
    Join Date
    Oct 2001
    Posts
    745

    template

    I have a template class as follows:
    I would like to make it a singelton class;
    I did some thing as follows:,But It is showing me errors...

    template<class _base>
    class Writerublic _base

    {
    public:

    }

    static Writer<_base>* Instance();

    };

    template<class _base>
    Writer<_base>* Writer<_base>::Instance()
    {
    static WriterThread<_base> theWriter();
    return &theWriter;
    }

    Is it right?

    Thanks in advance

  2. #2
    Join Date
    Jun 2002
    Posts
    224

    Re: template

    At first glance.

    Code:
    template<class _base>
    class Writer : public _base
    {
     public:
    
     } // syntax error
      static Writer<_base>* Instance();
    };
    
    template<class _base>
    Writer<_base>* Writer<_base>::Instance()
    {
      static WriterThread<_base> // WriterThread should be Writer
        theWriter(); // function declaration, not constructor
      return &theWriter;
    }

    Regards,
    ZDF

    What is good is twice as good if it's simple.
    "Make it simple" is a complex task.

  3. #3
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    No compile errors with some changes:

    Code:
    template<class _base>
    class Writer : public _base
    {
    public:
    	static Writer<_base>* Instance()
    	{
    		return theWriter;
    	}
    
    private:
    	static Writer<_base>* theWriter;
    };
    Is this what you're looking for?

    Jeff

  4. #4
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    Please don't post the same message on multiple forums. It's very annoying. I really hate to see something I answered already answered on another forum. I feel you've just wasted my time.

    Jeff

  5. #5
    Join Date
    Oct 2001
    Posts
    745
    Iam Really sorry for that.Iam posting on multiple forums, to make sure that everyone sees it & to definetly get a reply back.

    Once again Iam sorry for the inconvenience that it caused you.

  6. #6
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    At the very least, if you just can't resist, you should wait a bit before posting to the other forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured