c++ - Cannot find class domain_error in Standard C++ library
- Jim Jennings (43/43) Mar 28 2003 From Moo & Koenig, "Accelerated C++:
- Richard Grant (7/11) Mar 29 2003 Add this to your code:
- Jim Jennings (5/10) Mar 29 2003 template
- Jim Jennings (3/16) Mar 29 2003 Oops! I missed the smile.
- Jim Jennings (5/17) Mar 29 2003 template
-
Richard Grant
(6/8)
Mar 30 2003
Its debatable whether
should include the definition for std:... - Jim Jennings (9/17) Mar 30 2003 std::string
- Jim Jennings (3/29) Mar 30 2003 Or is it Stepanov's code, and who's who?
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) {} ~domain_error() _STLP_NOTHROW_INHERENTLY; }; ...*/
Mar 28 2003
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
"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, forwardtemplatereferences involved in conversions during a throw operation ;-)I'll take your word for it. It works now. Thanks again, Richard. Jim J.
Mar 29 2003
"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...Oops! I missed the smile.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, forwardtemplatereferences involved in conversions during a throw operation ;-)I'll take your word for it. It works now. Thanks again, Richard. Jim J.
Mar 29 2003
"Richard Grant" <fractal clark.net> wrote in message news:b65csj$gpq$1 digitaldaemon.com...In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...templateFrom 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, forwardreferences involved in conversions during a throw operation ;-) RichardBTW, I added it to Fomitchev's code where it belongs. ;o) Jim
Mar 29 2003
In article <b65qcc$pnm$1 digitaldaemon.com>, Jim Jennings says...BTW, I added it to Fomitchev's code where it belongs. ;o) JimIts 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
"Richard Grant" <fractal clark.net> wrote in message news:b6758n$1kbo$1 digitaldaemon.com...In article <b65qcc$pnm$1 digitaldaemon.com>, Jim Jennings says...std::stringBTW, I added it to Fomitchev's code where it belongs. ;o) JimIts debatable whether <stdexcept> should include the definition forinstead of declarations for std::string. In any case, it might be betterto getinto the habit of including <string> with <stdexcept> rather thanadjusting the<stdexcept> lib. This will make sure nothing breaks if/when you upgradestlport.RichardOK, that makes sense. But I still think stlport is missing the #include <string>. Jim J.
Mar 30 2003
"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...Or is it Stepanov's code, and who's who?In article <b62vcc$1oqn$1 digitaldaemon.com>, Jim Jennings says...templateFrom 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, forwardreferences involved in conversions during a throw operation ;-) RichardBTW, I added it to Fomitchev's code where it belongs. ;o) Jim
Mar 30 2003