Monday, January 26, 2015

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

Bo Persson <bop@gmb.dk>: Jan 26 12:38PM +0100

On 2015-01-25 20:28, DSF wrote:
 
> If it were a runtime error, I could track down the class involved.
> But as it stands, I'm stuck! Any ideas on how to track down this
> error?
 
It might be a namespace problem. If the operator== is not in the same
namespace as its class, the compiler will not find it.
 
 
Bo Persson
"Tobias Müller" <troplin@bluewin.ch>: Jan 26 05:36PM


> If it were a runtime error, I could track down the class involved.
> But as it stands, I'm stuck! Any ideas on how to track down this
> error?
 
Usually the compiler error message tells you that and more:
- the full template type
- all template parameters
- point of instatiation
etc
 
What compiler are you using?
 
Tobi
Paavo Helde <myfirstname@osa.pri.ee>: Jan 26 01:51PM -0600

DSF <notavalid@address.here> wrote in
 
> If it were a runtime error, I could track down the class involved.
> But as it stands, I'm stuck! Any ideas on how to track down this
> error?
 
My crystal ball tells me you are missing 'const' somewhere. But better post
the error message, even if it seems gibberish to you it may actually
contain information for others.
DSF <notavalid@address.here>: Jan 26 04:00PM -0500

On Mon, 26 Jan 2015 08:33:06 +1300, Ian Collins <ian-news@hotmail.com>
wrote:
 
>> Hello, group!
 
>> I have a template class that requires "==" to be overloaded in any
>> class that uses it. If the class doesn't overload "==", I get the
**>> compile time message "Illegal structure operation" on the "=="
>> template class or has "==" overloaded.
 
>You need to provide more detail - example code that fails to compile and
>the exact error message.
 
** No offense, but I gave you the exact error message.
 
Below is a mock-up of the problem.
 
For the pedants out there, yes I know include files aren't supposed
to have an extension. Dumbest idea! If you don't think so, try
searching an entire drive for all header files. Also, I prefer printf
over <<, so shoot me! :o)
 
As is, the code below will produce the "Illegal structure operation"
on the line:
return object == obj;
 
Remark out #define NOCOMPILE and it will compile and run.
 
This is because the first declaration for object Foo does not
overload operator ==, while the second does.
 
In my original source code, the TU that generates this error does
not even use the template represented by "Tester". All other TUs
compile error-free.
 
#include <stdio.h>
 
#define NOCOMPILE
 
#ifdef NOCOMPILE
class Foo
{
public:
Foo(int n) : num(n){};
 
private:
int num;
};
 
#else
 
class Foo
{
public:
Foo(int n) : num(n){};
friend bool operator==(const Foo& f1, const Foo& f2);
 
private:
int num;
};
 
inline bool operator==(const Foo& f1, const Foo& f2)
{
return f1.num == f2.num;
}

No comments: