Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #443

Why this behaviour for literal types?

From Andrzej Krzemieński<akrzemi1@gmail.com>
Newsgroups comp.std.c++
Subject Why this behaviour for literal types?
Date 2012-03-14 13:33 -0700
Organization http://groups.google.com
Message-ID <1615055.1458.1331755052471.JavaMail.geo-discussion-forums@vbgx21> (permalink)

Show all headers | View raw


Hi,
This is my literal type:

   struct C
   {
     double m;
     constexpr C( double m ) : m{m} {};
     constexpr double get() const { return m; };
   };

Therefore the following code works:

   constexpr C c = C{5.};
   constexpr double k = c.get();

But the following does not:

   const C cc = C{5.};  // but not constexpr
   constexpr double kk = cc.get();

Why is this so? Object cc is subject to const initialization anyway. It is possible to make it work only by a seemingly irrelevant change in declaration (add constexpr). What was the reason for disallowing this "implicit generation of compile-time constants"?

Regards,
&rzej


-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextNext in thread | Find similar


Thread

Why this behaviour for literal types? Andrzej Krzemieński<akrzemi1@gmail.com> - 2012-03-14 13:33 -0700
  Re: Why this behaviour for literal types? Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-03-15 11:33 -0700
    Re: Why this behaviour for literal types? Andrzej Krzemieński <akrzemi1@gmail.com> - 2012-03-17 00:53 -0700
      Re: Why this behaviour for literal types? Jason McKesson<jmckesson@gmail.com> - 2012-03-17 07:50 -0700
      Re: Why this behaviour for literal types? Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-03-18 11:31 -0700

csiph-web