title: How can I use static const members in CUDA?
body: <p>I am currently porting my ray tracer to the GPU by using CUDA, and to get my feet wet I am modifying the example CUDA 6.5 project (adding an array of integers) to use a custom Color struct instead of integer. However, I am getting various errors whenever I compile my code.</p>
  
  <p>I have all of my class's member functions declared with the <code>__host__</code> and <code>__device__</code> attributes, and I have all of the definition code in a <code>.cu</code> file. In my color struct, I have a <code>Darken</code> method that interpolates the given color to black by the given amount. I also have a static definition for black that the <code>Darken</code> function uses.</p>
  
  <p>For example, here is a trimmed down version of the struct:</p>
  
  <pre><code>// **********************
  //       .hpp file
  // **********************
  
  struct Color
  {
      float R;
      float G;
      float B;
  
      __host__ __device__ static Color Darken(const Color&amp; c, float amount);
  
      static Color Black;
  };
  
  // **********************
  //        .cu file
  // **********************
  
  const Color Color::Black( 1.0f, 1.0f, 1.0f );
  
  Color Color::Darken(const Color&amp; c, float amount)
  {
      return Color( Math::Lerp( c.R, Black.R, amount ),
                    Math::Lerp( c.G, Black.G, amount ),
                    Math::Lerp( c.B, Black.B, amount )  );
  }
  </code></pre>
  
  <p>However, whenever I go to compile the code, I get the following error:</p>
  
  <pre><code>error : identifier "rex::Color::Black" is undefined in device code
  </code></pre>
  
  <p>I have tried adding <code>__device__</code>, <code>__host__</code>, <code>__global__</code>, and various combinations of those specifiers to the colors, but the CUDA compiler tells me that they are not applicable. Also, after I add any of the specifiers to the static colors, I get the same error for the color's <code>R</code>, <code>G</code>, and <code>B</code> components.</p>
  
  <p>Does anyone know how I can use the static color definitions in CUDA?</p>