This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]