www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - template arguments

↑ ↓ ← Christof Meerwald <cmeerw web.de> writes:
See 14.3 Template arguments [temp.arg], paragraph 2, of the C++ standard:

#include <stdio.h>

template<class T> int f()
{
  return 0;
}

template<int I> int f()
{
  return 1;
}

int main()
{
  printf("%d\n", f<int()>()); // int() is a type-id: call the first f()
}


DM calls the second f().


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 14 2002
↑ ↓ → Christof Meerwald <cmeerw web.de> writes:
template<typename T>
struct A
{
  A(T *t)
    : t(t)
  { }

  int f()
  {
    return t(0);
  }

  T *t;
};

int f(int x)
{
  return x;
}

int main()
{
  A<int(int)> a(f);
  // Error: ')' expected
  a.f();

  return 0;
}


I guess this should also be allowed as a template argument (it's at least
the preferred syntax for Boost.Function).


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 22 2002