By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,405 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,405 IT Pros & Developers. It's quick & easy.

Operator << not valid on unsigned?

P: n/a
Hi.

I have a problem with a C++ code I can't resolve, or better, I can't see
what the problem should be!

Here's an excerpt of the incriminated code:

=== bspalgo.cpp

// THAT'S THE BAD FUNCTION!!
void save_bsp_tree( ofstream& of, bsptnodeptr p )
{
if( p->type == bsptnode::CUT ) {
of << (p->cut) << endl;
save_bsp_tree( of, p->below );
save_bsp_tree( of, p->above );
}
else {
if( p->type == bsptnode::IN )
of << "IN" << endl;
else if( p->type == bsptnode::OUT )
of << "OUT" << endl;
else
of << "!UNDEFINED!" << endl;
}
}

=== bsp.cpp

#include "bsp.h"

class bsptnode {
friend class bspt;
public:
enum Type {
CUT = 0x00,
...
};
enum {
UNDEFINED_CUT = unsigned(-1)
};

Type type;
unsigned cut; // <---- HERE'S THE BAD GUY!!
bsptnodeptr below;
bsptnodeptr above;
private:
...
};

=== bsp.h

#include "desf.h"

=== defs.h

typedef bsptnode* bsptnodeptr;
Now, if I compile this, I get:

boolalgo.cpp: In function `void save_bsp_tree(std::ofstream&, bsptnode*)':
boolalgo.cpp:67: error: no match for 'operator<<' in 'of <<
p->bsptnode::cut'
PlasmVector.h:143: note: candidates are: std::ostream&
operator<<(std::ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std::ostream&, const matrix&)
PlasmMatrix.h:69: note: std::ostream&
operator<<(std::ostream&, const PlasmMatrix&)
PlasmID.h:52: note: std::ostream&
operator<<(std::ostream&, const PlasmID&)
PlasmHyperPlane.h:168: note: std::ostream&
operator<<(std::ostream&, const PlasmHyperPlane&)
....
Now, bsptnodeptr is a redefinition of a pointer, and the member in
question is an unsigned... I really can't see what's going wrong. I'm
using gcc 4 under macosx.
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* Sensei:

I have a problem with a C++ code I can't resolve, or better, I can't see
what the problem should be!

Here's an excerpt of the incriminated code:

=== bspalgo.cpp

// THAT'S THE BAD FUNCTION!!
void save_bsp_tree( ofstream& of, bsptnodeptr p )
{
if( p->type == bsptnode::CUT ) {
of << (p->cut) << endl;
Now, if I compile this, I get:

boolalgo.cpp: In function `void save_bsp_tree(std::ofstream&, bsptnode*)':
boolalgo.cpp:67: error: no match for 'operator<<' in 'of <<
p->bsptnode::cut'


Note that the filename don't match the filename you've given, and the types
suggested by the compiler don't match the types in the code you've given.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2

P: n/a
Alf P. Steinbach wrote:
Note that the filename don't match the filename you've given, and the types
suggested by the compiler don't match the types in the code you've given.


I was trying to make the names simple... Ok, I'm trying to port a
software on osx 10.4 (gcc 4). At first I had:

PlasmArray.h: In member function `void PlasmArray<T>::clear()':
PlasmArray.h:68: error: there are no arguments to 'begin' that depend on
a template parameter, so a declaration of 'begin' must be available
PlasmArray.h:68: error: (if you use `-fpermissive', G++ will accept your
code, but allowing the use of an undeclared name is deprecated)
PlasmArray.h:68: error: there are no arguments to 'end' that depend on a
template parameter, so a declaration of 'end' must be available

Being PlasmArray:

template<class T>
class PlasmArray: public std::deque<T>
{
public:

so, in a function that used directly begin() and end(), I had to use
this->begin() and this->end() .... still wondering why.
Fixed that, in boolalgo.cpp if I include fstream, then I get:

/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc: In member function
`virtual typename std::basic_filebuf<_CharT, _Traits>::int_type
std::basic_filebuf<_CharT, _Traits>::underflow()':
/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc:277: error: expected
unqualified-id before '(' token
/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc: In member function
`virtual std::streamsize std::basic_filebuf<_CharT,
_Traits>::xsputn(const _CharT*, std::streamsize)':
/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc:585: error: expected
unqualified-id before '(' token
make[2]: *** [boolalgo.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

The only way to fix it, and I don't know why, is to delete the directive
#include <fstream>. Then I have:

=== boolalgo.cpp

#include "bsp.h"
//#include <fstream>
#include <queue>
#include <stack>

using namespace std;
....
void save_bsp_tree( ofstream& of, bsptnodeptr p )
{
if( p->type == bsptnode::CUT ) {
of << (p->cut) << endl;
save_bsp_tree( of, p->below );
save_bsp_tree( of, p->above );
}
else {
if( p->type == bsptnode::IN )
of << "IN" << endl;
else if( p->type == bsptnode::OUT )
of << "OUT" << endl;
else
of << "!UNDEFINED!" << endl;
}
}

=== bsp.h

#ifndef __BSP_H
#define __BSP_H
#ifdef WIN32
#pragma warning(disable:4786)
#endif
#include "GeneralDef.h"
class bsptnode {
friend class bspt;

public:
enum Type {
CUT = 0x00,
...
};
enum {
UNDEFINED_CUT = unsigned(-1)
};
Type type;
unsigned cut;
bsptnodeptr below;
bsptnodeptr above;
private:
bsptnode( const bsptnode& );
bsptnode& operator=( const bsptnode& );
public:
bsptnode():type(OUT),cut(UNDEFINED_CUT),below(0),a bove(0) {}
bsptnode(Type t):type(t),cut(UNDEFINED_CUT),below(0),above(0) {}
bsptnode(Type t, unsigned c):type(t),cut(c),below(0),above(0) {}

~bsptnode() {
if (above)
delete above;
if (below)
delete below;
}
};

=== GeneralDef.h

#ifndef _GENERAL_DEFS_H__
#define _GENERAL_DEFS_H__
#ifdef WIN32
#pragma warning (disable:4786)
#endif
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <math.h>
#include <assert.h>

class bspt;
class bsptnode;
class hyperplanes;
class ISystem;
class equation;

typedef bspt* bsptptr;

typedef bsptnode* bsptnodeptr;

===END===

Compiling it:

boolalgo.cpp: In function `void save_bsp_tree(std::ofstream&, bsptnode*)':
boolalgo.cpp:70: error: no match for 'operator<<' in 'of <<
p->bsptnode::cut'
PlasmVector.h:143: note: candidates are: std::ostream&
operator<<(std::ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std::ostream&, const matrix&)
PlasmMatrix.h:69: note: std::ostream&
operator<<(std::ostream&, const PlasmMatrix&)
PlasmID.h:52: note: std::ostream&
operator<<(std::ostream&, const PlasmID&)
....
PlasmArray.h:136: note: std::basic_ostream<char,
std::char_traits<char> >& operator<<(std::basic_ostream<char,
std::char_traits<char> >&, const PlasmArray<PlasmHyperPlane>&)
GeneralDef.h:184: note: std::ostream&
operator<<(std::ostream&, const PlasmSet&)
PlasmFastArray.h:248: note: std::basic_ostream<char,
std::char_traits<char> >& operator<<(std::basic_ostream<char,
std::char_traits<char> >&, const PlasmFastArray<PlasmIndex>&)
bsp.h:95: note: std::ostream& operator<<(std::ostream&,
const equation&)
bsp.h:228: note: std::ostream& operator<<(std::ostream&,
bspt&)
bsp.h:251: note: std::ostream& operator<<(std::ostream&,
ISystemData&)
bsp.h:303: note: std::ostream& operator<<(std::ostream&,
ISystem&)
....
GeneralDef.h:184: note: std::ostream&
operator<<(std::ostream&, const PlasmSet&)
PlasmFastArray.h:248: note: std::basic_ostream<char,
std::char_traits<char> >& operator<<(std::basic_ostream<char,
std::char_traits<char> >&, const PlasmFastArray<PlasmIndex>&)
bsp.h:95: note: std::ostream& operator<<(std::ostream&,
const equation&)
bsp.h:228: note: std::ostream& operator<<(std::ostream&,
bspt&)
bsp.h:251: note: std::ostream& operator<<(std::ostream&,
ISystemData&)
bsp.h:303: note: std::ostream& operator<<(std::ostream&,
ISystem&)

***continuing reading I find also:

boolalgo.cpp:78: error: no match for 'operator<<' in 'of << "OUT"'
PlasmVector.h:143: note: candidates are: std::ostream&
operator<<(std::ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std::ostream&, const matrix&)
PlasmMatrix.h:69: note: std::ostream&
operator<<(std::ostream&, const PlasmMatrix&)
....
boolalgo.cpp:80: error: no match for 'operator<<' in 'of << "!UNDEFINED!"'
PlasmVector.h:143: note: candidates are: std::ostream&
operator<<(std::ostream&, const PlasmVector&)
....

***and at last:

boolalgo.cpp: In function `void save_bsp(char*, bsptnode*, hyperplanes)':
boolalgo.cpp:176: error: variable 'std::ofstream of' has initializer but
incomplete type
make[2]: *** [boolalgo.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
sensei:plasm$
Jul 23 '05 #3

P: n/a
* Sensei:
Alf P. Steinbach wrote:
Note that the filename don't match the filename you've given, and the types
suggested by the compiler don't match the types in the code you've given.
I was trying to make the names simple... Ok, I'm trying to port a
software on osx 10.4 (gcc 4). At first I had:

PlasmArray.h: In member function `void PlasmArray<T>::clear()':
PlasmArray.h:68: error: there are no arguments to 'begin' that depend on
a template parameter, so a declaration of 'begin' must be available
PlasmArray.h:68: error: (if you use `-fpermissive', G++ will accept your
code, but allowing the use of an undeclared name is deprecated)
PlasmArray.h:68: error: there are no arguments to 'end' that depend on a
template parameter, so a declaration of 'end' must be available

Being PlasmArray:

template<class T>
class PlasmArray: public std::deque<T>
{
public:

so, in a function that used directly begin() and end(), I had to use
this->begin() and this->end() .... still wondering why.


The class inherited from is not a concrete class but a template. Whether
it has being() and end() members depends in principle on the type T. So
you have to tell the compiler that those are inherited members.

An alternative to qualification with "this->" is to declare the members via
'using':

using std::deque<T>::begin();
using std::deque<T>::end();

What you don't say is where the heck this PlasmArray is located and how the
compiler knows about it: it's not referenced in the code you present.

In other words:

* You're not providing the RELEVANT code, and

* It seems like at least some #include directive is omitted in the
code you present, as compared to the actual code.
Fixed that, in boolalgo.cpp if I include fstream, then I get:

/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc: In member function
`virtual typename std::basic_filebuf<_CharT, _Traits>::int_type
std::basic_filebuf<_CharT, _Traits>::underflow()':
/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc:277: error: expected
unqualified-id before '(' token
/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc: In member function
`virtual std::streamsize std::basic_filebuf<_CharT,
_Traits>::xsputn(const _CharT*, std::streamsize)':
/usr/include/gcc/darwin/4.0/c++/bits/fstream.tcc:585: error: expected
unqualified-id before '(' token
make[2]: *** [boolalgo.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

The only way to fix it, and I don't know why, is to delete the directive
#include <fstream>.
That's certainly not a fix, it's hiding the error behind some other error
or arbitrary effect.

The errors indicate a missing semicolon at the end of a class definition,
but it could really be anything.

Without the code it's difficult to say.

Then I have:

=== boolalgo.cpp

#include "bsp.h"
//#include <fstream>
#include <queue>
#include <stack>

using namespace std;
...
void save_bsp_tree( ofstream& of, bsptnodeptr p )
{
if( p->type == bsptnode::CUT ) {
of << (p->cut) << endl;
save_bsp_tree( of, p->below );
save_bsp_tree( of, p->above );
}
else {
if( p->type == bsptnode::IN )
of << "IN" << endl;
else if( p->type == bsptnode::OUT )
of << "OUT" << endl;
else
of << "!UNDEFINED!" << endl;
}
}

=== bsp.h

#ifndef __BSP_H
#define __BSP_H
#ifdef WIN32
#pragma warning(disable:4786)
#endif
#include "GeneralDef.h"
class bsptnode {
friend class bspt;

public:
enum Type {
CUT = 0x00,
...
};
enum {
UNDEFINED_CUT = unsigned(-1)
};
Type type;
unsigned cut;
bsptnodeptr below;
bsptnodeptr above;
private:
bsptnode( const bsptnode& );
bsptnode& operator=( const bsptnode& );
public:
bsptnode():type(OUT),cut(UNDEFINED_CUT),below(0),a bove(0) {}
bsptnode(Type t):type(t),cut(UNDEFINED_CUT),below(0),above(0) {}
bsptnode(Type t, unsigned c):type(t),cut(c),below(0),above(0) {}

~bsptnode() {
if (above)
delete above;
if (below)
delete below;
}
};

=== GeneralDef.h

#ifndef _GENERAL_DEFS_H__
#define _GENERAL_DEFS_H__
#ifdef WIN32
#pragma warning (disable:4786)
#endif
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <math.h>
#include <assert.h>

class bspt;
class bsptnode;
class hyperplanes;
class ISystem;
class equation;

typedef bspt* bsptptr;

typedef bsptnode* bsptnodeptr;

===END===

Compiling it:

boolalgo.cpp: In function `void save_bsp_tree(std::ofstream&, bsptnode*)':
boolalgo.cpp:70: error: no match for 'operator<<' in 'of <<
p->bsptnode::cut'
PlasmVector.h:143: note: candidates are: std::ostream&
operator<<(std::ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std::ostream&, const matrix&)
PlasmMatrix.h:69: note: std::ostream&
operator<<(std::ostream&, const PlasmMatrix&)
PlasmID.h:52: note: std::ostream&
operator<<(std::ostream&, const PlasmID&)


Presumably this would be fixed by including <fstream> in [boolalgo.cpp].

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.