Thursday, January 22, 2015

Digest for comp.lang.c++@googlegroups.com - 25 updates in 4 topics

Melzzzzz <mel@zzzzz.com>: Jan 17 03:06PM +0100

On Sat, 17 Jan 2015 13:51:52 +0000
> before friend and after
 
> Template friend
 
> friend Template
 
template <> friend Vector2D<T> operator*(...)
Melzzzzz <mel@zzzzz.com>: Jan 17 02:38PM +0100

On Sat, 17 Jan 2015 13:36:56 +0000
 
> But if I try to compile this it gives an error: "error: declaration
> of 'operator*' as non-function|"
 
> Why is it not working for me?
 
Perhaps you should put template keyword?
JiiPee <no@notvalid.com>: Jan 17 01:36PM

On 17/01/2015 13:19, Victor Bazarov wrote:
 
> Please read the FAQ 5.8 _carefully_. You can find the FAQ to this
> newsgroup here: http://www.parashift.com/c++-faq-lite/
 
> Victor
 
I actually did read (quite carefully) that and tried it, but it did not
work. But I now double checked, tried again, and still not working. On
site it says (
http://www.parashift.com/c++-faq-lite/template-friends.html ) :
 
"one simple approach is pre-declare each template friend function /above/"
 
I did that (pls see my code)....
 
Then it says:
"Also you add <> in the friend lines, as shown:
 
friend Foo<T> operator+ <> (const Foo<T>& lhs, const Foo<T>& rhs);
 
"
 
I also did that, then my line becomes:
 
friend Vector2D<T> operator * <> (const T& pointXY, const Vector2D<T>&
point);
 
But if I try to compile this it gives an error: "error: declaration of
'operator*' as non-function|"
 
Why is it not working for me?
Victor Bazarov <v.bazarov@comcast.invalid>: Jan 17 09:12AM -0500

On 1/17/2015 9:03 AM, Louis Krupp wrote:
>> 'operator*' as non-function|"
 
>> Why is it not working for me?
 
> Can you post a complete code sample that reproduces the problem?
 
I wonder how long it will take JiiPee to re-read FAQ 5.8 and follow the
instructions.
 
V
--
I do not respond to top-posted replies, please don't ask
JiiPee <no@notvalid.com>: Jan 17 01:51PM

On 17/01/2015 13:38, Melzzzzz wrote:
>> of 'operator*' as non-function|"
 
>> Why is it not working for me?
> Perhaps you should put template keyword?
 
I tried all 4 combinations (template, <>) and none worked. Template
before friend and after
 
Template friend
 
friend Template
JiiPee <no@notvalid.com>: Jan 17 02:19PM

On 17/01/2015 14:13, Victor Bazarov wrote:
> read the template section of the FAQ but because I wanted you to
> follow *exactly* the recommendation on how to post questions about the
> code that does not work correctly.
 
oh I see... ok, If the error remains I do that.
 
 
 
> Keep in mind that templates need to be instantiated (i.e. *used*) to
> be analyzed by the compiler and linker.
 
yes i know... i did that.
 
I ll try to find myself the error... if not I post complete code.
JiiPee <no@notvalid.com>: Jan 17 02:34PM

On 17/01/2015 14:31, Öö Tiib wrote:
> "it didn't work, I tried again, it didn't work". To me all compiler's
> also give errors in the lines of "I have no idea what is
> Coordinate2D.", also ... I can not see problems with that friend.
 
ok, i just posted a complete code
Victor Bazarov <v.bazarov@comcast.invalid>: Jan 17 09:13AM -0500

On 1/17/2015 8:51 AM, JiiPee wrote:
> before friend and after
 
> Template friend
 
> friend Template
 
<sigh> I pointed you to the question 5.8 not because I wanted you to
read the template section of the FAQ but because I wanted you to follow
*exactly* the recommendation on how to post questions about the code
that does not work correctly. Did you? Did you post a complete code?
Did you post the compiler output verbatim? ... And all that needs to be
in the same message! It's not enough to *desire* help.
 
Please, post the complete code that we could copy-and-paste into our
development environment to be compiled (or tried to be compiled).
Please post *verbatim* the compiler error you get (we don't all have the
same compiler as you.
 
Keep in mind that templates need to be instantiated (i.e. *used*) to be
analyzed by the compiler and linker.
 
Do you get me?
 
V
--
I do not respond to top-posted replies, please don't ask
JiiPee <no@notvalid.com>: Jan 17 02:10PM

On 17/01/2015 14:06, Melzzzzz wrote:
> template <> friend
 
"error: explicit specialization in non-namespace scope 'class
ct::Vector2D<T>'|"
 
but... the foo-example on the site works... so maybe I have to check
very carefully what is the difference... just cannot find it... somebody
help :)
JiiPee <no@notvalid.com>: Jan 17 02:33PM

Ok, here is the error code which can be compiled. I posted the
foo-version from the site which works.. so cannot see what is the
difference:
 
template <typename T> class Vector2D2;
template <typename T> Vector2D2<T> operator * (const T& pointXY, const
Vector2D2<T>& point);
 
template <typename T>
class Vector2D2
{
public:
// error: none of these works...
friend Vector2D2<T> operator* <> (const T& pointXY, const
Vector2D2<T>& point);
// friend Vector2D2<T> operator* (const T& pointXY, const
Vector2D2<T>& point);
T b;
};
 
template <typename T>
Vector2D2<T> operator* (const T& pointXY, const Vector2D2<T>& point)
{
Vector2D2<T> cc;
cc.b = point.b * pointXY;
return cc;
}
 
int main()
{
Vector2D2<double> jj;
3.0 * jj;
}
JiiPee <no@notvalid.com>: Jan 17 02:35PM

On 17/01/2015 14:03, Louis Krupp wrote:
> Can you post a complete code sample that reproduces the problem?
 
> Louis
 
Just posted it.
JiiPee <no@notvalid.com>: Jan 17 02:14PM

On 17/01/2015 13:19, Victor Bazarov wrote:
 
> Please read the FAQ 5.8 _carefully_. You can find the FAQ to this
> newsgroup here: http://www.parashift.com/c++-faq-lite/
 
> Victor
 
Ok, I compiled the site example, and it works. So obviously in my code
there is something I cannot find. I ll try to double check..
 
site example which works:
 
template<typename T> class Foo; // pre-declare the template class itself
template<typename T> Foo<T> operator+ (const Foo<T>& lhs, const Foo<T>&
rhs);
 
template<typename T>
class Foo {
public:
Foo(T const& value = T());
friend Foo<T> operator+ <> (const Foo<T>& lhs, const Foo<T>& rhs);
private:
T value_;
};
 
template<typename T>
Foo<T>::Foo(T const& value)
: value_(value)
{ }
 
template<typename T>
Foo<T> operator+ (const Foo<T>& lhs, const Foo<T>& rhs)
{ return Foo<T>(lhs.value_ + rhs.value_); }
JiiPee <no@notvalid.com>: Jan 17 12:54PM

So I have this global function which I want to be a friend of a class. I
tried all kind of combinations after googling but none worked so far. If
anybody remembers how to do this would be nice, thanks. Here is the code:
 
// forwards declaring things for the template function - from google...
template <typename T>
class Vector2D;
 
template <typename T>
Vector2D<T> operator * (const T& pointXY, const Vector2D<T>& point);
 
// my class
template <typename T>
class Vector2D : public Coordinate2D<T>
{
public:
// this is what I tried last time.. does not work
friend Vector2D<T> operator * (const T& pointXY, const Vector2D<T>&
point);
};
 
// the global function implementation:
template <typename T>
inline Vector2D<T> operator * (const T& pointXY, const Vector2D<T> & point)
{
return point * pointXY;
}
Victor Bazarov <v.bazarov@comcast.invalid>: Jan 17 08:19AM -0500

On 1/17/2015 7:54 AM, JiiPee wrote:
> {
> return point * pointXY;
> }
 
Please read the FAQ 5.8 _carefully_. You can find the FAQ to this
newsgroup here: http://www.parashift.com/c++-faq-lite/
 
Victor
--
I do not respond to top-posted replies, please don't ask
red floyd <no.spam.here@its.invalid>: Jan 17 09:18AM -0800

On 1/17/2015 6:14 AM, JiiPee wrote:
 
> template<typename T>
> Foo<T> operator+ (const Foo<T>& lhs, const Foo<T>& rhs)
> { return Foo<T>(lhs.value_ + rhs.value_); }
 
Better, but what *ERROR* messages did you receive?
JiiPee <no@notvalid.com>: Jan 17 05:09PM

On 17/01/2015 16:34, Paavo Helde wrote:
> Like ::operator* or mynamespace::operator*.
 
> hth
> Paavo
 
in base class/with base class? Ok, thanks... I ll try this.
JiiPee <no@notvalid.com>: Jan 17 06:17PM

On 17/01/2015 18:12, Paavo Helde wrote:
> cannot be sure.
 
> Cheers
> Paavo
 
yes true, I did not give the inheritance code. I gave the
non-inheritance version which actually works...
 
I ll check this myself ... i have not yet tried to fix the base class. I
ll come back if I fail to do it.
JiiPee <no@notvalid.com>: Jan 17 05:48PM

On 17/01/2015 17:18, red floyd wrote:
>> Foo<T> operator+ (const Foo<T>& lhs, const Foo<T>& rhs)
>> { return Foo<T>(lhs.value_ + rhs.value_); }
 
> Better, but what *ERROR* messages did you receive?
 
in the other post I explain that the error is related to the base
class.... so if I dont inherite anything then it does compile. So this
is one of these where I though the error was there but it was somewhere
else (it has to do with the base class *-operation function ... they
somehow conflict.... i ll check this later).
red floyd <no.spam.here@its.invalid>: Jan 17 07:11PM -0800

On 1/17/2015 9:48 AM, JiiPee wrote:
> is one of these where I though the error was there but it was somewhere
> else (it has to do with the base class *-operation function ... they
> somehow conflict.... i ll check this later).
 
I'm glad you found the error, but if you hadn't... My point was that
5.8 tells you how to post problems.
 
1. Post the code
2. Name the compiler and system
3. Post your errors.
JiiPee <no@notvalid.com>: Jan 18 12:23PM

On 18/01/2015 03:11, red floyd wrote:
 
> 1. Post the code
> 2. Name the compiler and system
> 3. Post your errors.
 
 
yes true. although if its a very simple issue, like one line, i guess
its not necessary all those. But here yes...
 
am still trying to figure out what causes it.
 
ram@zedat.fu-berlin.de (Stefan Ram): Jan 17 09:04PM

>In 2014, C++14 was »ratified« or »adopted«. But it seems not to
>have been published by the ISO yet. So, is it in effect or not?
 
A snippet from a SERP:
 
|ISO/IEC 14882:2015 - Information technology -- Programming ...
|www.iso.org/iso/catalogue_detail.htm?csnumber=64029
|ISO/IEC 14882:2014 specifies requirements for implementations ...
 
Can't they make up their mind whether it is »:2015« or »:2014«?
 
But it was not published in 2014, so when the ISO,
/possibly/, will manage to publish it in 2015, will
it be called »ISO/IEC 14882:2015«?
ram@zedat.fu-berlin.de (Stefan Ram): Jan 17 11:52PM

>I agree. It is good policy that your code-base produces no warnings.
 
I use -Wall and -Wextra, but then I disable some warnings
that I do not agree with. What consitutes a warning depends
on the compiler and the compiler options chosen and is to
some extend arbitrary.
 
I would not like to have arbitrary decisions rule my code.
Therefore, when I am sure that I like the code the way it
is, I would not change it just to silence a warning. So I
would feel unlucky, when I would be forced to do this by
-Werr.
 
However, I prefer code to produce no warnings (as you write
above), because you can't easily see whether a warning was
already accepted by you to be ignored or is a new warning
that has not been investigated yet (in fewer words: old
warnings might hide new warnings). Therefore, I prefer to
have no warnings, even without them being classified as
errors. When I do not agree with the author of the warning,
I use -Wno-..., otherwise I change my code.
 
An exceptionđ might be maintaining an old code-base that
generates thousands of warnings (while the application
generated might actually be working without obvious
problems). One cannot investigate all these warnings in the
near future. In this case, getting rid of all warnings is
more a long-term goal. For the time being, one might try to
investigate the most alarming warnings only.
 
When you use -Wall -Wextra -Werr on such a project and have
a fixed date when it must compile, there even is a risk that
the code that generates those warning errors is modified in
a hurry and this introduces new semantic errors (that will
not be flagged by the compiler) into the code.
agent@drrob1.com: Jan 17 09:39AM -0500

I am learning c++ after many years of modula-2. To my eye, assignment
operator is := and equality comparison is =.
 
In ubuntu 14.04, is there a compiler switch for g++ that flags any
embedded assignment statements. This is to help me when I intend ==
instead of =
 
Thanks
agent@drrob1.com: Jan 17 02:04PM -0500

On Sat, 17 Jan 2015 10:49:49 -0700, Louis Krupp
 
>I recommend -Werr as well as -Wall. If you can get your code to
>compile with no warnings, you don't need to worry about which ones to
>fix and which to ignore.
 
Thanks guys for your help.
 
--rob
JiiPee <no@notvalid.com>: Jan 17 03:18PM

it was the inheritance what caused the problem.. so something in base
class. The template works. So if I change the operator from * to % for
example, then everything compiles. So in base class there is also * -
operator which gave troubles :).
 
Well, the advice to make a code which you guys can compile it helped to
find this out.
 
Now just have to check the base class why this happens....
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: