[Bug c++/20547] undefined reference to "static const" fields of classes
pinskia at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sat Mar 19 14:34:00 GMT 2005
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-19 14:34 -------
(In reply to comment #5)
> I understand what you mean.
> But why the following codes works:
>
> #include <iostream>
> #include <vector>
>
> struct T
> {
> static char const a = 3;
> };
>
> std::vector<char> ddd;
>
> int
> main()
> {
> ddd.push_back(static_cast<char>(T::a)); // <========= here
>
> std::cerr << ddd.front() << std::endl;
>
> return 0;
> }
>
> and if I pass an constant to a function which takes its address,
Because you changed an lvalue to a rvalue.
> then why the folloing codes doesn't produce errors?
Because constants are rvalues so there is going to be a temporary variable made for you.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20547
More information about the Gcc-bugs
mailing list