I am trying to create own manipulator, which will add the extra tab with input. Please find when I run the below program I got below mentioned error. could you please anybody help me, what is the wrong with the code? - #include <iostream>
-
#include <cstdlib>
-
-
using namespace std;
-
-
class addtab
-
{
-
-
addtab()
-
{
-
cout << "constructer has called" << endl;
-
}
-
~addtab()
-
{
-
cout << "destructer has called" << endl;
-
}
-
public:
-
friend ostream& operator<<(ostream& ,int&);
-
};
-
ostream& operator<<(ostream &os,int &n)
-
{
-
return os ;
-
}
-
-
int main()
-
{
-
-
int n;
-
n = 7;
-
cout << "this " << addtab(n) << endl;
-
}
-
-
when I run this program, I am getting below mentioned error? please help me to clear my error.
-
-
-
create_own_manu.cpp: In function `int main()':
-
create_own_manu.cpp:30: no matching function for call to `addtab::addtab(int&)'
-
create_own_manu.cpp:7: candidates are: addtab::addtab(const addtab&)
-
create_own_manu.cpp:10: addtab::addtab(
-
)
9 2469
First, you do not 'run' it - it doesn't even compile, and in order to run it, you need to compile it. As the error message states, you want to use addtab::addtab(int) constructor in line 30, but there is no such constructor declared.
Hi,
Not a C++ programmer even though I am trying a bit.
int main()
{
int n;
n = 7;
cout << "this " << addtab(n) << endl;
}
look at cout
you tried addtab(n). Even if you made a constructor that receive an integer as parameter, you will get an error.
why? cause if you call a function or whatever in cout it must have to return something(but not void)(and if I am not wrong). And you cant define any return type for a constructor.
Best Regards,
Johny
A manipulator must take only one argument, an ostream& and return and ostream&. - ostream& MyManipulator(ostream& os)
-
{
-
-
//do my stuff:
-
os << etc....
-
-
return os.
-
-
}
oh I forgot to add in the first place
int main()
{
int n;
n = 7;
cout << "this " << addtab(n) << endl;
}
addtab is a class not a object of any class. But It seems that you are tring to use it as variable! Not that clear to me :)
What do you think :)
any body can tell me , can we write the own manipulator in c++, if we can , can you provide some links for Example/ some sample program..
addtab is a class not a object of any class. But It seems that you are tring to use it as variable! Not that clear to me :)
This is just fine. All objects are variables but some objects can be used as functions. These are called functors and they are classes that implement the function operator, operator()().
can we write the own manipulator in c++, if we can
Yes, but it has have one argument, ostream&, and it must return am ostream&: - ostream& StarBar(ostream& os)
-
{
-
os.write("*****", 5);
-
return os;
-
}
-
-
-
cout << StarBar << "--" << StarBar<< endl;
can we write a own manipulater with single argument.
Yes.
However, your manipulator must have this prototype: - ostream& MyManipulator(ostream&);
If your manipulator needs input values then you need to get them from elsewhere than through function arguments. You would normally use a Singleton object to get the values or maybe call a function that gets the values for you.
Thanks for all your reply
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steven T. Hatton |
last post by:
I tried to create my own manipulator that would both set the width of the
subsequent output field, and cast an unsigned char to unsigned in. I came
up with the following rather ugly hack. Notice...
|
by: stoptv |
last post by:
Hello group, this is my dilemma:
------------------------------------------------------------------------
#include <iostream>
using namespace std;
// a regular manipulator
ostream & hello(...
|
by: jack |
last post by:
I have a class which overloads the insertion operator '<<' for every
type that ostream handles. I do this so that I can use my class a
direct replacement for cout and cerr where the insertion...
|
by: Xah Lee |
last post by:
there's this one i can't figure out.
I'm trying to kick out image.google.com's top frame when it goes to my
page.
If you go to
http://images.google.com/images?q=milk+tits
click on the page...
|
by: Xah Lee |
last post by:
Frameset Infinity!
http://xahlee.org/js/frame2/frameset.html
HTML Frame tutorial + Infinity!
http://xahlee.org/js/frame/0.html
Xah
xah@xahlee.org
∑ http://xahlee.org/
|
by: youpak2000 |
last post by:
What you can't find in programing text books
Professional software development needs more knowledge than language
syntax,
OOP, styles, etc. There are many things which people usually learn by...
|
by: Colloid Snake |
last post by:
Hello,
I was attempting to configure log4cpp to monitor some logs on my *nix box, and when I run 'make' I get this error message:
# make
g++ -DHAVE_CONFIG_H -I. -I. -I../include...
|
by: Xah Lee |
last post by:
Of Interest:
Introduction to 3D Graphics Programing
http://xahlee.org/3d/index.html
Currently, this introduction introduces you to the graphics format of
Mathematica, and two Java Applet...
|
by: Xah Lee |
last post by:
On Java's Interface
Xah Lee, 20050223
In Java the language, there's this a keyword “interface”.
In a functional language, a function can be specified by its name and
parameter specs....
|
by: barcaroller |
last post by:
When I use an iostream manipulator in a cout statement, it seems to affect
all subsequent cout statements.
cout << x << endl; // dec by default
cout << hex << x << endl; // hex
cout <<...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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 projectplanning, coding, testing,...
| |