Thursday, October 8, 2015

Digest for comp.lang.c++@googlegroups.com - 9 updates in 5 topics

"K. Frank" <kfrank29.c@gmail.com>: Oct 08 03:22PM -0700

Hello fl!
 
On Wednesday, October 7, 2015 at 9:14:13 AM UTC-4, fl wrote:
> return q.display(os);
> }
> ...
 
I will comment on the "inline" part of your question:
(But, yes, this is a "free" function, i.e., not on a member
function, and that's okay.)
 
One practical reason to inline a free function is that you
can then include the function's implementation in a header
file. (This may or may not be relevant to your tutorial
or use case.)
 
I find this a convenience for simple little classes:
 
point.h:
 
#include <ostream>
 
struct Point {
double x = 0.0;
double y = 0.0;
};
 
inline std::ostream& operator<<(std::ostream &os, const Point p) {
return os << '(' << p.x << ", " << p.y << ')';
}
 
You can now include point.h in multiple translation units
(multiple .cpp files) without getting a multiple-definition
error at link time.
 
Normally one would be advised to put more complicated
implementation is a separate .cpp file, but for this
kind of trivial little helper function, it's convenient
to just put everything into one header file and be done
with it (especially in example or tutorial code).
 
 
Best.
 
 
K. Frank
Mark <i@dontgetlotsofspamanymore.net>: Oct 08 08:27AM +0100

On 7 Oct 2015 16:40:12 GMT, Jorgen Grahn <grahn+nntp@snipabacken.se>
wrote:
 
> std::vector<int>::iterator i = v.begin();
> *i = 42;
>}
 
This doesn't compile:
Error: Cannot use const int* to initialize int*.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Oct 08 05:14PM

On Thu, 2015-10-08, Mark wrote:
>>}
 
> This doesn't compile:
> Error: Cannot use const int* to initialize int*.
 
With Sun C++, the one that accepted your first piece of code?
 
/That/ I didn't expect: the code above was supposed to trigger the
same bug as yours. I just removed the typedefs and classes and
pointers which obscured the problem a bit.
 
The message you get (must be on the v.begin() line, right?) seems to
indicate that their std::vector<T>::iterator is just a fancy name for
T*. So at least we know that the std::vector you use there is not of
the best quality ... I don't think it's illegal in any way to define
the iterator like that, but it's more polite to the programmer to make
it a distinct type.
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Mark <i@dontgetlotsofspamanymore.net>: Oct 08 07:07PM +0100

On 8 Oct 2015 17:14:26 GMT, Jorgen Grahn <grahn+nntp@snipabacken.se>
wrote:
 
 
>> This doesn't compile:
>> Error: Cannot use const int* to initialize int*.
 
>With Sun C++, the one that accepted your first piece of code?
 
Yep. The same compiler.
 
>same bug as yours. I just removed the typedefs and classes and
>pointers which obscured the problem a bit.
 
>The message you get (must be on the v.begin() line, right?)
 
Yes.
 
>the best quality ... I don't think it's illegal in any way to define
>the iterator like that, but it's more polite to the programmer to make
>it a distinct type.
 
TBH some of the subleties of this escape me ATM.
Paavo Helde <myfirstname@osa.pri.ee>: Oct 08 12:31AM -0500

arthur.rubin.669@gmail.com wrote in
 
> I may be missing something obvious, but the following code compiles
> for me, but gives an unspecified linker error.
 
We are not chiromancers here, please include the error message.
 
> #include <iostream> // for cout and cin [not yet implemented]
> #include <vector>
> class Decimal {
[...]
> friend ostream& operator<< (ostream& os, Decimal s) ;
 
Should be std::ostream, there is no using directive.
arthur.rubin.669@gmail.com: Oct 08 04:29AM -0700

On Wednesday, October 7, 2015 at 10:32:18 PM UTC-7, Paavo Helde wrote:
 
> > I may be missing something obvious, but the following code compiles
> > for me, but gives an unspecified linker error.
 
> We are not chiromancers here, please include the error message.
 
The message really was "link error". It appears that there was a mismatch of characteristics like "const" between a function declaration and implementation, which led a misspelled unresolved external. But the message didn't say that.
 
I attempted to delete the post, and it's deleted on Google groups, but no one else accepts a cancel.
 
--
Arthur Rubin
"Öö Tiib" <ootiib@hot.ee>: Oct 08 07:07AM -0700


> > We are not chiromancers here, please include the error message.
 
> The message really was "link error". It appears that there was a mismatch of characteristics like "const" between a function declaration and implementation, which led a misspelled unresolved external. But the message didn't say that.
 
> I attempted to delete the post, and it's deleted on Google groups, but no one else accepts a cancel.
 
Google just deletes a post from its Usenet client. Usenet is over decade
older than web, Google can't delete anything from it.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Oct 08 01:20PM

On Wed, 2015-07-15, Richard wrote:
...
> from Win32 then you'll want something more automated.
 
> On the flip side, sometimes you end up with better architecture as a
> side benefit of creating the insulting domain specific layer. You end
^^^^^^^^^
You mean "insulating", but the typo was amusing ;-)
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
arthur.rubin.669@gmail.com: Oct 07 09:13PM -0700

I may be missing something obvious, but the following code compiles for me, but gives an unspecified linker error. Compiler is C++ Builder 10. (And, yes, the body is still a test program. There will be more.)
 
Main program:
 
#ifdef _WIN32
#include <tchar.h>
#else
typedef char _TCHAR;
#define _tmain main

No comments: