constructors and references

C

copx

This compiles:

struct FileWriterI; struct FileWriter {
FileWriterI& self;
FileWriter(FileWriterI& i) : self(i) {}
}

This does not:

struct FileWriterI; struct FileWriter {
FileWriterI& self;
FileWriter(FileWriterI& i) : self{i} {}
}

Why? Why can't I initialize references using {} in constructors? I use
GCC 4.7.0, c++11 mode.
 
V

Victor Bazarov

This compiles:

struct FileWriterI; struct FileWriter {
FileWriterI& self;
FileWriter(FileWriterI& i) : self(i) {}
}

This does not:

struct FileWriterI; struct FileWriter {
FileWriterI& self;
FileWriter(FileWriterI& i) : self{i} {}
}

Why? Why can't I initialize references using {} in constructors? I use
GCC 4.7.0, c++11 mode.

Maybe because the braces aren't part of the C++ syntax for the member
initializers... Just a wild guess... Brackets won't work, either. Nor
will angle brackets... Only parentheses.

V
 
C

copx

This compiles:

struct FileWriterI; struct FileWriter {
FileWriterI& self;
FileWriter(FileWriterI& i) : self(i) {}
}

This does not:

struct FileWriterI; struct FileWriter {
FileWriterI& self;
FileWriter(FileWriterI& i) : self{i} {}
}

Why? Why can't I initialize references using {} in constructors? I use
GCC 4.7.0, c++11 mode.

Finally found the answer:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50025

It's a bug in the C++11 standard itself!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top