This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Why does template constuctor only work at global scope? Bug?
- From: Ben Bridgwater <bbridgwater at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 14 Oct 2009 15:09:20 -0400
- Subject: Why does template constuctor only work at global scope? Bug?
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