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

Threaded View

  1. #1
    Join Date
    Dec 2008
    Posts
    26

    Unhappy How to define a method with a generic parameter

    Hello everyone !

    I think i've solved the problem.

    like this :
    Code:
    template <class myType>
        void TestEmpty(myType object);

    I want to implement my own exception class, and i need to define a method with a generic parameter.

    something like this:

    Code:
    void Test_Empty(T object) {
        
       if (obj==NULL)  /* the object type is unknown at compilation time*/
        cout<< "No data exception";
      
    }
    The problem is that I do not know how to define a default type parameter of my test function.
    Once it can be of type int, other wise of type float for instance.
    Can you please give me some suggestions.
    Last edited by munteanu24d; July 7th, 2009 at 10:38 AM.

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