473,651 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overloading operator>> - class errors

5 New Member
I have a class that I believe should work. I've compared it to previous programs I've written, compared it to examples from my professor, to examples in my textbook, but can't see why I get the errors I get when building.

All errors take place in the line
Expand|Select|Wrap|Line Numbers
  1. friend istream& operator>>(istream& ins, QuadPolyn& P);
Please note this is NOT an assignment, just an example of what we should be able to do.

Expand|Select|Wrap|Line Numbers
  1. #ifndef quadpolyn_h
  2. #define quadpolyn_h
  3.  
  4. class QuadPolyn
  5. {
  6. friend istream& operator>>(istream& ins, QuadPolyn& P);
  7.  
  8. public:
  9.     QuadPolyn();
  10.     QuadPolyn(double a2, double a1, double a0);
  11.     double At(double v) const;
  12.     bool Valid() const;
  13.     bool getRoots(double& r1, double& r2);
  14.  
  15. private:
  16.     double a, b, c; // coefficients
  17. };
  18.  
  19. #endif
error C2143: syntax error : missing ';' before '&'
error C2433: 'istream' : 'friend' not permitted on data declarations
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2061: syntax error : identifier 'istream'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2805: binary 'operator >>' has too few parameters
Apr 4 '07 #1
3 2679
horace1
1,510 Recognized Expert Top Contributor
once I had included <iostream> your fragment of code compiles OK using g++, Visual C and C Builder 5. What compiler are you using?
Apr 4 '07 #2
Demoris
5 New Member
once I had included <iostream> your fragment of code compiles OK using g++, Visual C and C Builder 5. What compiler are you using?
Visual Studio 2005. Tried to build again today, same errors.
Apr 4 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
I just compiled your code fragment using my Visual Studio,.NET 2005 and got no errors.

What does the rest of your code look like??

Remember, when you get an error from the compiler it points to the place where the compiler knew it was in trouble. That actual cause of the error can be anywhere from there to the top of the code in that file.
Apr 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
1759
by: maths_fan | last post by:
Can't understand how to overload these operations and for what reason?
3
2037
by: Alex Vinokur | last post by:
Member operators operator>>() and operator<<() in a program below work fine, but look strange. Is it possible to define member operators operator>>() and operator<<() that work fine and look fine? // --------- foo.cpp --------- #include <iostream> using namespace std;
4
2474
by: hall | last post by:
Hi all. I have run into a problem of overloading a templatized operator>> by a specialized version of it. In short (complete code below), I have written a stream class, STR, which defines a templatized operator>>() as a member that can deal with the built in C types (int, char, float...) template <class tType> STR& STR::operator>>(tType & t); I then attempted to add an overloaded version of this to support my own
4
1548
by: Ook | last post by:
I'm a but fuzzy about this. You would call it like this:Polynomial poly; // Polynomial is my class with various properties cin >> poly; In the function itself, I would, for example, do the following: istream& operator>>(istream& is, Polynomial& poly) { is >> poly._size; is >> poly._coefficient;
4
1872
by: Don Hedgpeth | last post by:
Here's a question - I'm new to c++ and I have two classes that overload the >> operator. One class calls the other...such as. //code for class1 friend std::istream& operator >> (std::istream& lhs, class1& rhs) { .....random code here return lhs:} //code for class2 private: class1 jimbo;
11
2071
by: Ashwin | last post by:
hi guys, i have overloaded >operator for my own string class .the function is as given below istream& operator>>(istream &in,string1 &s) { char *a; a=new char; in>>a; s=a;
2
2500
by: Wayne Marsh | last post by:
Hello, Is it considered sane/good practice to write a global operator for the insertion and extraction operators of an fstream in binary mode to serialize a binary class, or are they strictly meant for formatted text input and output? Let's imagine, for example, that I had a standard Windows BMP file (I am aware that C++ has no concept of a BMP - this is simply putting my question in a simple context). If I wanted to load it into a...
0
1244
by: Nico | last post by:
I want to create a const_iterator that gives me access to dynamically generated objects. For example see the class Polygon that contains a list of points stored as following doubles in a vector (x1, y1, x2, y2, ...). The iterator should return only pairs of doubles to avoid possible confusion of the user of the class Polygon. (The storage format is needed for conversion to other libraries.) The code for Polygon below compiles well, but...
9
2918
by: Nico | last post by:
I want to create a const_iterator that gives me access to dynamically generated objects. For example see the class Polygon that contains a list of points stored as following doubles in a vector (x1, y1, x2, y2, ...). The iterator should return only pairs of doubles to avoid possible confusion of the user of the class Polygon. (The storage format is needed for conversion to other libraries.) The code for Polygon below compiles well, but...
0
8349
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
8275
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
8795
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
8576
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...
1
6157
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
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
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
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.