473,889 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error: expected initializer before '&' token

can someone please comment on what i may be doing wrong here? i am
overloading input and output operators and keep getting this error.
here are the code snipets, thanks

friend ostream & operator <<(ostream & outs, const big_int &
source){
outs << source.get_b1() << " " << source.get_b2() ;
return outs;
}

friend istream & operator >>(istream & ins, const big_int &
target){
ins >> target.big_int1 >> target.big_int2 ;
return ins;
}

Mar 13 '06
16 42314
yes, the class has been protoyped in a header file and i have double
checked to make sure the #include "BigInt.h" is present at the top of
the implementation and driver programs. the .h file is included at the
top of the other two files before any functions are defined or called.
all overload functions are in the same file one after another as in the
example provided

Mar 13 '06 #11
andrew browning wrote:
correct... those are the lines where i get the error


You can't use the keyword "friend" outside a class definition.
Mar 13 '06 #12
That IS a strange error. I've never seen it before. One thing's for
sure, it's talking about the '&' next to the BigInt. I tried all kinds
of different things, but I couldn't figure it out. I guess this is where
I have to surrender this to the gurus =)

I do have one question that threw me for a loop. Why is it in your .cpp
file that you are able to use ostream and istream without the std::
prefix having not used a using directive (using namespace std;)?
Mar 13 '06 #13
andrew browning wrote:
perhaps this will simplify. below is the header and then the
implementation [snip]
friend ostream & operator <<(ostream & outs, const BigInt&
big_int1){
ITYM:

std::ostream & operator <<(std::ostre am & outs,
const BigInt& big_int1) {
outs << big_int1.get_b1 () << " " << big_int1.get_b2 ();
return outs;
}
friend istream & operator >>(istream & ins, const BigInt&
big_int1){
ITYM:
std::istream & operator >>(std::istre am & ins,
const BitInt& big_int1) {
ins >> target.big_int1 >> target.big_int2 ;
return ins;
}

}


HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 13 '06 #14
i wish i new... its my first time overloading input and output
operators. thanks ever so much for donating part of your sunday to
this.

Mar 13 '06 #15
your right. now can you explain where my logic fell down?????

Mar 13 '06 #16
andrew browning wrote:
andrew browning wrote:
perhaps this will simplify. below is the header and then the
implementation
[snip]

friend ostream & operator <<(ostream & outs, const BigInt&
big_int1){

ITYM:

std::ostream & operator <<(std::ostre am & outs,
const BigInt& big_int1) {

outs << big_int1.get_b1 () << " " << big_int1.get_b2 ();
return outs;
}
friend istream & operator >>(istream & ins, const BigInt&
big_int1){

ITYM:
std::istream & operator >>(std::istre am & ins,
const BitInt& big_int1) {

ins >> target.big_int1 >> target.big_int2 ;
return ins;
}

}

your right. now can you explain where my logic fell down?????

Please quote the appropriate amount of context. Fixed.

Elsethread, you seemed to think that you *could* use ostream and istream
without the `std::' in front of them -- but didn't know why. The answer
is that you couldn't, and can't (the error message *is* a confusing one).

The fact that `friend' is part of a class declaration, and not part of a
function signature was also pointed out elsethread.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 13 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5730
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ================================================================= Error 19: "CORBAManagerMessages.h", line 4 # Unexpected 'std'. using std::string; ^^^
9
6598
by: Ben Midgley | last post by:
Please have a look at the code below My problem is the error message "Nonportable pointer conversion", so far as I can tell there is no pointer conversion occuring here so I am assuming it is something implicit. The error is associated with the assignment { &MenuItemList }, when delcaring the mit_ZoneSelectMenu structure. I am using borland bcc32 the command line compiler which seems pretty good, I just dont understand this...
5
5696
by: cranium.2003 | last post by:
hi, Here is my code #include <iostream.h> int main() { cout <<"HI"; return 0; } and using following command to compile a C++ program g++ ex1.cpp -o ex1
2
1940
by: Suneeel | last post by:
Hi all, I'm new at templates. I've written this code and am compiling it with gcc 4.1.0 on RedHat Linux 9. /////////temptest.h////////////// template <class T> class tempclass { public:
1
1409
by: liuhaoran | last post by:
HI. i have a question about memory error. when i change double variable to float variable ,for example: int curGen = 0; double sum = 0; // m_iPopSize is int variable ,NewPop is a vector int NumToAdd = m_iPopSize - NewPop.size();
2
1876
by: Latina | last post by:
Hi, I am doing a program using overloded operators but I am getting some error, Can some one help please. Here is my code: #include<iostream> #include<string.h> #include<cctype> using namespace std;
2
8186
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; SELECT COUNT(*)INTO TOTAL_LEFT FROM DBSAMBA.REPORTEDTRANSACTION_S; WHILE (TOTAL_LEFT > 0) DO
6
14731
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing declerations.... #include <queue> #include <vector> #include <string> class database { queue<delayTP> delayThrouput;
9
11219
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list even then I should be able to get correct value for the array element. I need value and state to be present in a single byte thats why I use macros. Here is what my code look like: typedef enum
0
9967
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
11202
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
10792
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...
1
10895
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9611
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7151
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
5830
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
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3256
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.