CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Default arguments for class template parameters

    Is it possible to have a class that has template parameters, all of which have default values, so that you can use that class name without specifying a template parameter?

    My compiler seems to object to the following code

    Code:
    template <typename T = int>
    class A
    {
       ...
    };
    
    int main()
    {
        ...
        A x;
        ...
        return 0;
    }

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Default arguments for class template parameters

    Well...in general you can omit template arguments which does have a default argument, however, even if all template arguments have a default value, the angle brackets MUST be provided (even if they are empty)...thus...
    Code:
    A<> x;

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