www.digitalmars.com         C & C++   DMDScript  

c++ - Cannot find class domain_error in Standard C++ library

reply "Jim Jennings" <jwjenn mindspring.com> writes:
From Moo & Koenig, "Accelerated C++:

   1: // source file for the `median' function
   2: #include <algorithm>    // to get the declaration of `sort'
   3: #include <stdexcept>    // to get the declaration of `domain_error'
   4: #include <vector>       // to get the declaration of `vector'
   5:
   6: using std::domain_error; using std::sort;   using std::vector;
   7:
   8: #include "median.h"
   9:
  10: // compute the median of a `vector<double>'
  11: // note that calling this function copies the entire argument `vector'
  12: double median(vector<double> vec)
  13: {
  14:  typedef vector<double>::size_type vec_sz;
  15:
  16:  vec_sz size = vec.size();
  17:  if (size == 0)
  18:         throw domain_error("median of an empty vector");
  19:
  20:  sort(vec.begin(), vec.end());
  21:
  22:  vec_sz mid = size/2;
  23:
  24:  return size % 2 == 0 ? (vec[mid] + vec[mid-1]) / 2 : vec[mid];
  25: }
  26:
  27:

        throw domain_error("median of an empty vector");
                                                      ^
median.cpp(18) : Error: cannot find constructor for class matching
std::domain_error::std::domain_error(char *)
--- errorlevel 1

C:\dm\stlport\stlport\stdexcept, lines 88-94
/*...
class _STLP_CLASS_DECLSPEC domain_error : public logic_error {
public:
  domain_error(const string& __arg) : logic_error(__arg) {}
# ifdef _STLP_OWN_IOSTREAMS
  ~domain_error() _STLP_NOTHROW_INHERENTLY;
# endif
};
...*/
Mar 28 2003
parent reply Richard Grant <fractal clark.net> writes:
In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...
From Moo & Koenig, "Accelerated C++:

good choice of writers!
        throw domain_error("median of an empty vector");

median.cpp(18) : Error: cannot find constructor for class matching
std::domain_error::std::domain_error(char *)

Add this to your code: #include <string> Why? Probably a problem with typedefed, namespace qualified, forward template references involved in conversions during a throw operation ;-) Richard
Mar 29 2003
next sibling parent reply "Jim Jennings" <jwjenn mindspring.com> writes:
"Richard Grant" <fractal clark.net> wrote in message
news:b65csj$gpq$1 digitaldaemon.com...
 In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...
 Add this to your code:

 #include <string>

 Why? Probably a problem with typedefed, namespace qualified, forward

 references involved in conversions during a throw operation ;-)

Jim J.
Mar 29 2003
parent "Jim Jennings" <jwjenn mindspring.com> writes:
"Jim Jennings" <jwjenn mindspring.com> wrote in message
news:b65hbp$jqa$1 digitaldaemon.com...
 "Richard Grant" <fractal clark.net> wrote in message
 news:b65csj$gpq$1 digitaldaemon.com...
 In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...
 Add this to your code:

 #include <string>

 Why? Probably a problem with typedefed, namespace qualified, forward

 references involved in conversions during a throw operation ;-)

Jim J.

Mar 29 2003
prev sibling parent reply "Jim Jennings" <jwjenn mindspring.com> writes:
"Richard Grant" <fractal clark.net> wrote in message
news:b65csj$gpq$1 digitaldaemon.com...
 In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...
From Moo & Koenig, "Accelerated C++:

good choice of writers!
        throw domain_error("median of an empty vector");

median.cpp(18) : Error: cannot find constructor for class matching
std::domain_error::std::domain_error(char *)

Add this to your code: #include <string> Why? Probably a problem with typedefed, namespace qualified, forward

 references involved in conversions during a throw operation ;-)

 Richard

Jim
Mar 29 2003
next sibling parent reply Richard Grant <fractal clark.net> writes:
In article <b65qcc$pnm$1 digitaldaemon.com>, Jim Jennings says...

BTW, I added it to Fomitchev's code where it belongs. ;o)
Jim

Its debatable whether <stdexcept> should include the definition for std::string instead of declarations for std::string. In any case, it might be better to get into the habit of including <string> with <stdexcept> rather than adjusting the <stdexcept> lib. This will make sure nothing breaks if/when you upgrade stlport. Richard
Mar 30 2003
parent "Jim Jennings" <jwjenn mindspring.com> writes:
"Richard Grant" <fractal clark.net> wrote in message
news:b6758n$1kbo$1 digitaldaemon.com...
 In article <b65qcc$pnm$1 digitaldaemon.com>, Jim Jennings says...

BTW, I added it to Fomitchev's code where it belongs. ;o)
Jim

Its debatable whether <stdexcept> should include the definition for

 instead of declarations for std::string. In any case, it might be better

 into the habit of including <string> with <stdexcept> rather than

 <stdexcept> lib. This will make sure nothing breaks if/when you upgrade

 Richard

<string>. Jim J.
Mar 30 2003
prev sibling parent "Jim Jennings" <jwjenn mindspring.com> writes:
"Jim Jennings" <jwjenn mindspring.com> wrote in message
news:b65qcc$pnm$1 digitaldaemon.com...
 "Richard Grant" <fractal clark.net> wrote in message
 news:b65csj$gpq$1 digitaldaemon.com...
 In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...
From Moo & Koenig, "Accelerated C++:

good choice of writers!
        throw domain_error("median of an empty vector");

median.cpp(18) : Error: cannot find constructor for class matching
std::domain_error::std::domain_error(char *)

Add this to your code: #include <string> Why? Probably a problem with typedefed, namespace qualified, forward

 references involved in conversions during a throw operation ;-)

 Richard

Jim

Or is it Stepanov's code, and who's who?
Mar 30 2003