Thread: Templates with default types

  1. #1
    Confused Magos's Avatar
    Join Date
    Sep 2001

    Templates with default types

    Consider this structure:
    template<class T = double>
    struct Vector
        x = T(0);
        y = T(0);
      T x;
      T y;
    To create a structure you type:
    Vector<float> v1;
    Vector<> v2; //T = double
    However the <> is still needed even when using the default type. From a pedantic and visual standpoint I really find this ugly. Is there any way to make this work:
    Vector<float> v1;
    Vector v2; //T = double
    (without typedefing and appending letters like Vectorf, Vectord, Vectori etc...)


    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003

    "Vector<>" is required by the standard. You'll have to settle on a typedef or macro or whatever.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates vs Virtual
    By Dae in forum C++ Programming
    Replies: 2
    Last Post: 03-23-2009, 12:48 AM
  2. Switch statement / default:
    By kcpilot in forum C Programming
    Replies: 4
    Last Post: 12-02-2008, 03:14 PM
  3. Utilizing another compiled program for a task.
    By kotoroshinoto in forum C Programming
    Replies: 6
    Last Post: 06-03-2008, 01:43 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. Help with default parameter value using ptr-to-functor
    By registering in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2004, 04:21 PM