Hi all,
I am using msvc 7.1 and have encountered the following code:
-----------
A.hpp
-----------
class A
{
public:
class Vector : public std::vector< std::pair< int, bool > >
{
friend std::istream & operator>>(
const std::istream & is, Vector & v );
friend std:ostream & operator<< (
const std::ostream & os, const Vector & v );
};
const Vector & GetVector() const { return v; }
private:
Vector v;
};
-----------
B.hpp
-----------
namspace BLib
{
class B
{
void SomeFunc();
};
}
-----------
B.cpp
-----------
#include "B.hpp"
#include "A.hpp"
using namespace BLib;
void B::SomeFunc()
{
A a;
std::strstream ss;
ss << a;
}
When I try and compile B.cpp the compiler complains that it cannot
find a suitable overload for operator << that takes a right hand
argument of Vector (more specifically vector< pair< int, bool > > )
(C2679). If I remove class B from namespace BLib it compiles fine.
What am I doing wrong?
Thanks,
George Economos 4 1477
George Economos wrote: I am using msvc 7.1 and have encountered the following code:
----------- A.hpp -----------
class A { public:
class Vector : public std::vector< std::pair< int, bool > > { friend std::istream & operator>>( const std::istream & is, Vector & v );
friend std:ostream & operator<< ( const std::ostream & os, const Vector & v ); };
I really wish nobody attempted to _write_ code directly in their newsgroup
reader program. Can't you copy-and-paste?
Anyway, syntax errors aside, you define operators for the 'Vector' here. const Vector & GetVector() const { return v; }
private:
Vector v; };
[...] void B::SomeFunc() { A a;
std::strstream ss; ss << a;
And here you're trying to output an object of type A, for which no
operator<< is defined. What do you expect?
}
When I try and compile B.cpp the compiler complains that it cannot find a suitable overload for operator << that takes a right hand argument of Vector (more specifically vector< pair< int, bool > > ) (C2679). If I remove class B from namespace BLib it compiles fine. What am I doing wrong?
Everything. Try it again. And this time post _real_ code. See FAQ 5.8.
V
Thanks Victor for your help. Unfortunately I can't directly paste the
code as it is confidential.
Your right about SomeFunc(), it should have been defined as:
void B:SomeFunc()
{
A a;
std::strstream ss;
ss << a.GetVector();
}
If you have anything more constructive to say I would really
appreciate it.
Thanks Again,
-george
On Tue, 23 Aug 2005 10:20:51 -0400, Victor Bazarov
<v.********@com Acast.net> wrote: George Economos wrote: I am using msvc 7.1 and have encountered the following code:
----------- A.hpp -----------
class A { public:
class Vector : public std::vector< std::pair< int, bool > > { friend std::istream & operator>>( const std::istream & is, Vector & v );
friend std:ostream & operator<< ( const std::ostream & os, const Vector & v ); };
I really wish nobody attempted to _write_ code directly in their newsgroup reader program. Can't you copy-and-paste?
Anyway, syntax errors aside, you define operators for the 'Vector' here.
const Vector & GetVector() const { return v; }
private:
Vector v; };
[...] void B::SomeFunc() { A a;
std::strstream ss; ss << a;
And here you're trying to output an object of type A, for which no operator<< is defined. What do you expect?
}
When I try and compile B.cpp the compiler complains that it cannot find a suitable overload for operator << that takes a right hand argument of Vector (more specifically vector< pair< int, bool > > ) (C2679). If I remove class B from namespace BLib it compiles fine. What am I doing wrong?
Everything. Try it again. And this time post _real_ code. See FAQ 5.8.
V
George Economos wrote: Thanks Victor for your help. Unfortunately I can't directly paste the code as it is confidential.
[snip]
write a test case then. what you pasted was already a test case, you
just didn't try compiling it first. Please post code that produces the
same error, and only the same error, as your actual code.
George Economos wrote: Thanks Victor for your help. Unfortunately I can't directly paste the code as it is confidential.
Your right about SomeFunc(), it should have been defined as:
void B:SomeFunc() { A a; std::strstream ss; ss << a.GetVector(); }
If you have anything more constructive to say I would really appreciate it.
"More constructive"? Here you go...
(a) Don't top-post.
(b) Read the FAQ (http://www.parashift.com/c++-faq-lite/).
(c) This code:
-----------------------------------------------------------
#include <strstream>
#include <vector>
#include <utility>
class A
{
public:
class Vector : public std::vector<std ::pair<int,bool > >
{
/* notice that streams cannot be 'const' */
friend std::istream&
operator >>(std::istre am &, A::Vector &);
friend std::ostream&
operator <<(std::ostre am &, const A::Vector &);
};
const Vector& GetVector() const { return v; }
private:
Vector v;
};
namespace BLib
{
class B
{
void SomeFunc();
};
}
using namespace BLib;
void B::SomeFunc()
{
A a;
std::strstream ss;
ss << a.GetVector();
}
-----------------------------------------------------------
*compiles* without an error using VC++ v7.1.
So, I don't know what you do wrong since you didn't post the _real_ code
that gives you the error you claim to have seen. Thanks Again, -george
On Tue, 23 Aug 2005 10:20:51 -0400, Victor Bazarov <v.********@com Acast.net> wrote:
George Economos wrote:
I am using msvc 7.1 and have encountered the following code:
----------- A.hpp -----------
class A { public:
class Vector : public std::vector< std::pair< int, bool > > { friend std::istream & operator>>( const std::istream & is, Vector & v );
friend std:ostream & operator<< ( const std::ostream & os, const Vector & v ); };
I really wish nobody attempted to _write_ code directly in their newsgroup reader program. Can't you copy-and-paste?
Anyway, syntax errors aside, you define operators for the 'Vector' here.
const Vector & GetVector() const { return v; }
private:
Vector v; };
[...] void B::SomeFunc() { A a;
std::strstream ss; ss << a;
And here you're trying to output an object of type A, for which no operator<< is defined. What do you expect?
}
When I try and compile B.cpp the compiler complains that it cannot find a suitable overload for operator << that takes a right hand argument of Vector (more specifically vector< pair< int, bool > > ) (C2679). If I remove class B from namespace BLib it compiles fine. What am I doing wrong?
Everything. Try it again. And this time post _real_ code. See FAQ 5.8.
V
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andy Jarrell |
last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain
overloaded operators don't seem to come with the inheritance. For example:
// TestA.h ---------------------------------------
#include <iostream>
enum Aval
{
FIRST_VALUE,
|
by: N4M |
last post by:
Dear,
I have problems with overloaded operators ++() and --(). MSVC++ 6.0
compiler gives errors, one is shown as below:
"
c:\data\c++\mygraphs\graph.h(182) : error C2555: 'CGraphNodeIter::++'
: overriding virtual function differs from 'CGraphNodeIterI::++' only
by return type or calling convention
c:\data\c++\mygraphs\graph.h(141) : see...
|
by: Brad Eck |
last post by:
"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup's 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators 'take a name, rather than a value, as their
second operand and provide...
|
by: masood.iqbal |
last post by:
Please help me with this doubt that I have regarding overloaded
operators. Sometimes they are member functions and sometimes they are
friends (e.g. see the code snippet from Stroustrup, Second Edition that
I have posted to comp.sources.d). How do we decide which is more
appropriate? Why are the overloaded "<<" and ">>" operators always...
|
by: maadhuu |
last post by:
hi
i wasnt to know the answer for the following.
now ,u can overload all the operators which are basically determined at
runtime (coz' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like
p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined...
| |
by: ambar.shome |
last post by:
Hi,
As you know there are few operators in C++ which cant be overloaded.
They are:
.., .*, ::, ?: , new , delete , sizeof , typeid , static_casr ,
dynamic_cast , const_cast , reinterpret_cast .
Theremust be some reason for this restriction for each of the
|
by: Riku Jarvinen |
last post by:
Hello everyone,
I have a logging class which writes program outputs to the logfile. The
class works fine as long as only C++ native data types are considered. The
problem is that I have a program with a bunch of classes which have the
output stream operators << of their own. The overloaded operators work fine
when inserted into the std:cout...
|
by: Ross |
last post by:
I have a problem regarding the precedence of overloaded cast operators.
My program is as follows:
#include <stdio.h>
class A;
class B {
public:
B(A &a) {
|
by: raylopez99 |
last post by:
I need an example of a managed overloaded assignment operator for a
reference class, so I can equate two classes A1 and A2, say called
ARefClass, in this manner: A1=A2;. For some strange reason my C++.NET
2.0 textbook does not have one. I tried to build one using the format
as taught in my regular C++ book, but I keep getting compiler...
|
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...
|
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. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |