Why does template constuctor only work at global scope? Bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can anyone tell me why this template constructor only works at global scope?

Is this a g++ bug (I'm using g++ 4.5)?

// g++ -std=c++0x t.cpp

class T {
public:
 template<int N>
 T(int (&a)[N]) {}
};

T t1 = (int[]) {1, 2, 3}; // OK

int main(int argc, char **argv)
{
 T t2 = (int[]) {1, 2, 3}; // error: conversion from 'int [3]' to
non-scalar type 'T' requested
}

I realize I could use a std::initializer_list<int> constructor
instead, but I'm curious why what I'm trying doesn't work.

Thanks,
Ben

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux