472,371 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Operator << not valid on unsigned?

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
3 2821
* 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
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
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Guenther Brunthaler | last post by:
Hi template specialists, I have a problem with the code listed below. What I wanted to do is defining an operator<< that is able to output a 'matrix<ELEMENT_T, INDEX_T>::subrange' object into...
1
by: tsunami | last post by:
hi I am confused while writing member functions I have declared them as public members of the class class BitArray{ public: BitArray& operator <<(int); //overloaded left shift operator...
0
by: ma740988 | last post by:
Consider #include <iostream> #include <string> #include <map> using namespace std; struct dstream // data_stream class {
14
by: lutorm | last post by:
Hi everyone, I'm trying to use istream_iterators to read a file consisting of pairs of numbers. To do this, I wrote the following: #include <fstream> #include <vector> #include <iterator> ...
3
by: Carlo Capelli | last post by:
I found a change in the following code, that behaved correctly in VC++ 6. #include <strstream> using namespace std; void main() { char x; ostrstream(x, 100) << "pippo" << "pluto" << ends;...
3
by: Yudan Yi \(OSU\) | last post by:
I have a question to define a friend operator<< for a class. for example, I can define friend ostream& operator<<(ostream& os, const TTest& x) { ...; return (os); }; While I want to add more...
8
by: CodeCracker | last post by:
Is it possible to write such an operator function? watch that there is a space in between unsigned and long. Does this mean I have to write two operator function one for long and another for...
17
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks...
2
by: Peter Lee | last post by:
ASSUME unsigned int = 32 bits #q1 unsigned int u1 = 3u << 0u valid? #q2 unsigned int u2 = 3u >0u valid? #q3 unsigned int u3 = 3u << 32u valid? #q4 unsigned int u4 = 3u >32u valid?
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.