Template neglects const (why?)
        Posted  
        
            by 
                Gabriel
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Gabriel
        
        
        
        Published on 2012-11-07T16:05:57Z
        Indexed on 
            2012/11/07
            17:00 UTC
        
        
        Read the original article
        Hit count: 213
        
Does somebody know, why this compiles??
template< typename TBufferTypeFront, typename TBufferTypeBack = TBufferTypeFront>
class FrontBackBuffer{
public:
  FrontBackBuffer(
    const TBufferTypeFront  front, 
    const TBufferTypeBack back):    ////const reference  assigned to reference???
     m_Front(front),
     m_Back(back)
  {
  };
  ~FrontBackBuffer()
  {};
  TBufferTypeFront m_Front;       ///< The front buffer
  TBufferTypeBack m_Back;         ///< The back buffer
};
int main(){
    int b;
    int a;
    FrontBackBuffer<int&,int&> buffer(a,b); //
    buffer.m_Back = 33;
    buffer.m_Front = 55;
}
I compile with GCC 4.4. Why does it even let me compile this? Shouldn't there be an error that I cannot assign a const reference to a non-const reference?
© Stack Overflow or respective owner