Mark <i@dontgetlotsofspamanymore.net>: Oct 07 07:48AM +0100 On 6 Oct 2015 16:27:06 GMT, Jorgen Grahn <grahn+nntp@snipabacken.se> wrote: >"legacy" above sounds to me as a hint that it once did ... but I >cannot think of a way that a standard library or compiler would allow >it. I can't answer this. This is my first involvement in this code but, like you, assume it once did compile -- but with a different compiler on a different OS. |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Oct 07 09:02AM On Wed, 2015-10-07, Mark wrote: >>>> > I am trying to build some legacy C++ code. Much of the code uses the >>>> > std::vector class and fails to compile. I have created a simple >>>> > example which also gives the same error: ... > I can't answer this. This is my first involvement in this code but, > like you, assume it once did compile -- but with a different compiler > on a different OS. Well, I /both/ assume it did -- and at the same time cannot think of any circumstances where that could happen! Can anyone else here? (To me it's just an intellectual exercise, but I guess that if the code never did compile, that would be important information for you ... perhaps you got the wrong version of the code?) /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Mark <i@dontgetlotsofspamanymore.invalid>: Oct 07 11:26AM +0100 On 7 Oct 2015 09:02:50 GMT, Jorgen Grahn <grahn+nntp@snipabacken.se> wrote: >(To me it's just an intellectual exercise, but I guess that if the >code never did compile, that would be important information for you >... perhaps you got the wrong version of the code?) I've just tried it with Sun C++ 5.8 Patch 121017-14 on Solaris 5.10 and it did compile! -- (\__/) M. (='.'=) If a man stands in a forest and no woman is around (")_(") is he still wrong? |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Oct 07 04:40PM On Wed, 2015-10-07, Mark wrote: >>... perhaps you got the wrong version of the code?) > I've just tried it with Sun C++ 5.8 Patch 121017-14 on Solaris 5.10 > and it did compile! Weird! So then this obviously broken code compiles too? #include <vector> void foo(const std::vector<int>& v) { if(v.empty()) return; std::vector<int>::iterator i = v.begin(); *i = 42; } I seem to recall that Sun had a low-quality standard library and that people often used a third-party replacement, but that was a decade ago ... /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
Vir Campestris <vir.campestris@invalid.invalid>: Oct 07 09:56PM +0100 On 07/10/2015 17:40, Jorgen Grahn wrote: > I seem to recall that Sun had a low-quality standard library and that > people often used a third-party replacement, but that was a decade ago That rings a bell. I have a vague feeling that _ages_ ago Microsoft had a library where iterator and const_iterator were typedefs of the same thing. Andy |
fl <rxjwg98@gmail.com>: Oct 07 06:13AM -0700 Hi, When I read a tutorial code, I feel a little surprise about an inline function inline std::ostream& operator<<(std::ostream &os, const Query &q) { return q.display(os); } It is called here: Query q; cout << "\nExecuting Query for: " << q << endl; class Query is defined as: class Query { public: Query(const std::string&); // builds a new WordQuery // copy control to manage pointers and use counting Query(const Query &c): q(c.q), use(c.use) { ++*use; } ~Query() { decr_use(); } Query& operator=(const Query&); // interface functions: will call corresponding Query_base operations std::set<TextQuery::line_no> eval(const TextQuery &t) const { return q->eval(t); } std::ostream &display(std::ostream &os) const { return q->display(os); } private: Query(Query_base *query): q(query), use(new std::size_t(1)) { } Query_base *q; std::size_t *use; void decr_use() { if (--*use == 0) {delete q; delete use; } } }; Things I feel strange are that it looks like this inline function is about an operator '<<'. Is it still an overloading? Then, this overloading function is not a class member function. If that is OK, I can define any operator overloading function, not a member function for a class? Thanks, |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Oct 07 08:16PM +0100 fl <rxjwg98@gmail.com> writes: <snip> > Things I feel strange are that it looks like this inline function is about > an operator '<<'. Is it still an overloading? Yes. > Then, this overloading > function is not a class member function. That's right. It's a plain old-fashioned function. > If that is OK, I can define any > operator overloading function, not a member function for a class? Pretty much. Overloading based on argument type is a general mechanism in C++, and it is often used with plain functions. operator<< is a very common case. -- Ben. |
Paavo Helde <myfirstname@osa.pri.ee>: Oct 07 12:12AM -0500 fl <rxjwg98@gmail.com> wrote in > project, I find the set type used are different in declaration and > definition, through it can build well through. > Here is the declaration of class function 'eval': You mean "member function". > BinaryQuery(left, right, "&") { } > // concrete class: AndQuery inherits display and defines remaining > pure virtual std::set<line_no> eval(const TextQuery&) const; There is no 'pure' keyword in C++ AFAIK. Anyway, the return type of eval is std::set<line_no>. The type line_no is not defined here, it probably comes from a base class (TextQuery?) > set<TextQuery::line_no> > AndQuery::eval(const TextQuery& file) const > { Here, the type is set<TextQuery::line_no>. Assuming that there is a using directive or declaration so that 'set' resolves to 'std::set' and that TextQuery is a base class of AndQuery so that TextQuery::line_no is the same type than line_no inside AndQuery definition, these types are the same. What's the problem? BTW, one needs to explicitly write TextQuery::line_no here because the return type is textually placed "outside" of the member function definition body and thus "cannot see" the names inside the class or inherited classes without qualification. This is a quirk of C++ syntax. > typedef std::vector<std::string>::size_type line_no; > It has a 'vector<std::string>', which is the same as > 'std::set<line_no> '? Is the writing OK? No, std::vector is not the same as std::set, if that's what you ask. But line_no is just defined as a synonym of the type 'size_type' from vector, so there is actually no vector around. The vector<T>::size_type type is just an unsigned integer type, typically 32- or 64-bit. So the std::set involved here is just a set of integers. hth Paavo |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment