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 - 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. - #ifndef quadpolyn_h
-
#define quadpolyn_h
-
-
class QuadPolyn
-
{
-
friend istream& operator>>(istream& ins, QuadPolyn& P);
-
-
public:
-
QuadPolyn();
-
QuadPolyn(double a2, double a1, double a0);
-
double At(double v) const;
-
bool Valid() const;
-
bool getRoots(double& r1, double& r2);
-
-
private:
-
double a, b, c; // coefficients
-
};
-
-
#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
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?
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: maths_fan |
last post by:
Can't understand how to overload these operations and for what reason?
|
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;
|
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
|
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;
|
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;
| |
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;
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |