Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,381 of 33,346    |
|    Francis Glassborow to DeMarcus    |
|    Re: Can you please help me explain const    |
|    06 Jul 11 12:23:50    |
   
   From: francis.glassborow@btinternet.com   
      
   On 06/07/2011 00:03, DeMarcus wrote:   
   > Hi,   
   >   
   > Why doesn't this compile?   
   >   
   > class MyClass   
   > {   
   > public:   
   > MyClass( int i ) : i_(i) { /* non-const ops */ }   
   >   
   > constexpr int f() const { return i_; }   
   >   
   > private:   
   >   
   > const int i_;   
   > };   
   >   
   >   
   > In gcc4.6.1 I get   
   > error: enclosing class of ‘int MyClass::f() const’ is not a literal type   
   >   
   > To me f() only uses a constant, so what can go wrong?   
      
   I think that at least part of the problem is that 1_ is not a compile time   
   constant. IIRC constexpr must be evaluated at compile time.   
      
   { trailing quotation removed -- please do it yourself. -mod }   
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca