C++: Error:class undelared (first use in this function). But I got it declared in hpp file
<p>I created a class declaration file as fixed.hpp and class definition in fixed.cpp. When I create a object in the main function. The compiler told me that the class is not declared. But I think I did. Any idea or help? Thanks.</p>

<hr>

<p>This is the main.cpp:</p>

<pre><code>    #include &lt;iostream&gt;
    #include &lt;istream&gt;
    #include &lt;ostream&gt;
    #include &lt;sstream&gt;
    #include &lt;stdexcept&gt;

    #include "test.hpp"
    #include "fixed.hpp"

    int main(int argc, char *argv[])
    { using namespace std;
      fixed f1;
      cout&lt;&lt;f1.value()&lt;&lt;endl;
    }
</code></pre>

<hr>

<p>This is the fixed.hpp:</p>

<pre><code>    #ifndef FIXED_HPP_
    #define FIXED_HPP_

    typedef float value_type ; 

    class fixed
    {
     public:
       fixed();
       fixed(value_type integer, value_type fraction); 
       fixed(double val);

       void as_string();
       value_type integer();
       value_type fraction();
       value_type value();
       static const int places=4;    
       static const int places10=10000;  //scale factor

     private:
       value_type integer_;
       value_type fraction_;   
       //value_type result_;

    };
</code></pre>

<hr>

<p>This is the fixed.cpp:</p>

<pre><code>    #include "fixed.hpp"

    #include &lt;iostream&gt;
    #include &lt;ostream&gt;
    #include &lt;stdexcept&gt;
    #include &lt;string&gt;


    using namespace std;

    //static const value_type fixed::places(4);
    //static const value_type fixed::places10(10000);
    fixed::fixed():integer_(0), fraction_(0){}

    fixed::fixed(value_type                     integer,value_type                         fraction):integer_(integer), fraction_(fraction) 
           {try
       {
        if (fraction_ &lt;0)                          
           throw invalid_argument("Invalid argument. Must be positive.");
       }
    catch (exception&amp; e)
      {
        cout &lt;&lt;"\n"&lt;&lt; e.what() &lt;&lt; endl;
      }
     while (fraction_&gt;= places10)
        {
         if(int(fraction_)%10 &gt;=5 &amp;&amp; fraction_&lt; (places10*10) )
            fraction_=fraction_/10+1;               
         else
            fraction_/=10;
        }

     //result_ = integer_ + fraction_/places10;  //??
   } 

    fixed::fixed(double val):integer_(int (val)), fraction_(         (val- int(val))*places10) 
           { if (val &lt;0)
        {    val = val*(-1);
             if ( int(val*places10*10)%10&gt;=5)
              fraction_ = (fraction_*(-1) +1)*(-1);
        }     
     else
         {
          if (int(val*places10*10)%10&gt;=5)
              fraction_ = fraction_ +1;
         }

     //result_ = integer_ + fraction_/places10;  //??
   }

    void fixed::as_string()
           {    string str;
                string str2;
                while( (int(integer_)/10) &gt;=0 and int(integer_)&gt;0 )
             {
             str.push_back(int(integer_)%10 + 48);
             integer_ = integer_/10;
             //cout&lt;&lt;str&lt;&lt;endl;
             }
        //cout&lt;&lt;"String format: "&lt;&lt;str&lt;&lt;endl;
        reverse(str.begin(), str.end());
        //cout&lt;&lt;"Reversed format: "&lt;&lt;str&lt;&lt;endl;
        str.push_back('.');
        //cout&lt;&lt;"New string: "&lt;&lt;str&lt;&lt;endl;
        while( (int(fraction_)/10 )&gt;=0 and int(fraction_)&gt;0)
             {
             str2.push_back(int(fraction_)%10 + 48);
             fraction_ = fraction_/10;
             //cout&lt;&lt;str&lt;&lt;endl;
             }
        //cout&lt;&lt;"String format: "&lt;&lt;str&lt;&lt;endl;
        reverse(str2.begin(), str2.end());
        str.append(str2);
        cout&lt;&lt;"String representation: "&lt;&lt;str&lt;&lt;endl;
           }


    value_type fixed::value()
         {
          return   integer_ + fraction_/places10;     
         }
    value_type fixed::integer()
         {
          return integer_;
         }
    value_type fixed::fraction()
         {
          return fraction_;
         }
</code></pre>
