473,738 Members | 3,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(s td::ofstream&, bsptnode*)':
boolalgo.cpp:67 : error: no match for 'operator<<' in 'of <<
p->bsptnode::cu t'
PlasmVector.h:1 43: note: candidates are: std::ostream&
operator<<(std: :ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std: :ostream&, const matrix&)
PlasmMatrix.h:6 9: 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 2952
* 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(s td::ofstream&, bsptnode*)':
boolalgo.cpp:67 : error: no match for 'operator<<' in 'of <<
p->bsptnode::cu t'


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_file buf<_CharT, _Traits>::int_t ype
std::basic_file buf<_CharT, _Traits>::under flow()':
/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_file buf<_CharT,
_Traits>::xsput n(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(UNDEF INED_CUT),below (0),above(0) {}
bsptnode(Type t):type(t),cut( UNDEFINED_CUT), below(0),above( 0) {}
bsptnode(Type t, unsigned c):type(t),cut( c),below(0),abo ve(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(s td::ofstream&, bsptnode*)':
boolalgo.cpp:70 : error: no match for 'operator<<' in 'of <<
p->bsptnode::cu t'
PlasmVector.h:1 43: note: candidates are: std::ostream&
operator<<(std: :ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std: :ostream&, const matrix&)
PlasmMatrix.h:6 9: note: std::ostream&
operator<<(std: :ostream&, const PlasmMatrix&)
PlasmID.h:52: note: std::ostream&
operator<<(std: :ostream&, const PlasmID&)
....
PlasmArray.h:13 6: note: std::basic_ostr eam<char,
std::char_trait s<char> >& operator<<(std: :basic_ostream< char,
std::char_trait s<char> >&, const PlasmArray<Plas mHyperPlane>&)
GeneralDef.h:18 4: note: std::ostream&
operator<<(std: :ostream&, const PlasmSet&)
PlasmFastArray. h:248: note: std::basic_ostr eam<char,
std::char_trait s<char> >& operator<<(std: :basic_ostream< char,
std::char_trait s<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:18 4: note: std::ostream&
operator<<(std: :ostream&, const PlasmSet&)
PlasmFastArray. h:248: note: std::basic_ostr eam<char,
std::char_trait s<char> >& operator<<(std: :basic_ostream< char,
std::char_trait s<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:1 43: note: candidates are: std::ostream&
operator<<(std: :ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std: :ostream&, const matrix&)
PlasmMatrix.h:6 9: note: std::ostream&
operator<<(std: :ostream&, const PlasmMatrix&)
....
boolalgo.cpp:80 : error: no match for 'operator<<' in 'of << "!UNDEFINED !"'
PlasmVector.h:1 43: 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:17 6: 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_file buf<_CharT, _Traits>::int_t ype
std::basic_file buf<_CharT, _Traits>::under flow()':
/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_file buf<_CharT,
_Traits>::xsput n(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(UNDEF INED_CUT),below (0),above(0) {}
bsptnode(Type t):type(t),cut( UNDEFINED_CUT), below(0),above( 0) {}
bsptnode(Type t, unsigned c):type(t),cut( c),below(0),abo ve(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(s td::ofstream&, bsptnode*)':
boolalgo.cpp:70 : error: no match for 'operator<<' in 'of <<
p->bsptnode::cu t'
PlasmVector.h:1 43: note: candidates are: std::ostream&
operator<<(std: :ostream&, const PlasmVector&)
matrix.h:96: note: std::ostream&
operator<<(std: :ostream&, const matrix&)
PlasmMatrix.h:6 9: 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
3843
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 a 'std::basic_ostream<charT, traits>'. For some reason, it does not work. The compiler always complains:
1
1422
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 BitArray& operator>>(int); //overloaded right shift operator I have declared private data members as: private:
0
1410
by: ma740988 | last post by:
Consider #include <iostream> #include <string> #include <map> using namespace std; struct dstream // data_stream class {
14
2336
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> using namespace std;
3
1589
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; // here x contains "004400C8pluto"
3
1595
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 control to the output by an additional parameter, can I do in the following way? friend ostream& operator<<(ostream& os, const TTest& x, unsigned parameter) { switch (parameter)
8
3248
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 unsigned? Regards,
17
2329
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 << endl;
2
2413
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?
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.