Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
March 29, 2003 Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
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 }; ...*/ |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | 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 |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Grant | "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 template > references involved in conversions during a throw operation ;-) > I'll take your word for it. It works now. Thanks again, Richard. Jim J. |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | "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 > template > > references involved in conversions during a throw operation ;-) > > > I'll take your word for it. It works now. Thanks again, Richard. Jim J. > > Oops! I missed the smile. |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Grant | "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 template > references involved in conversions during a throw operation ;-) > > Richard > > BTW, I added it to Fomitchev's code where it belongs. ;o) Jim |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | 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 |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim Jennings | "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 > template > > references involved in conversions during a throw operation ;-) > > > > Richard > > > > > BTW, I added it to Fomitchev's code where it belongs. ;o) Jim Or is it Stepanov's code, and who's who? |
March 30, 2003 Re: Cannot find class domain_error in Standard C++ library | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Grant | "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 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 > OK, that makes sense. But I still think stlport is missing the #include <string>. Jim J. |
Copyright © 1999-2021 by the D Language Foundation