Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 6th, 2006, 11:28 PM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing an object to a manipulator function

hello friends,

i want to pass an object as an argument as follows.

#include <iomanip>
#include <iostream>
using namespace std;

class myclass
{
public :
    int m,n;

    myclass(){m=10;n=12;}
};

ostream & disp( ostream & output,myclass &obj)
{
output<<"Hello"<<endl;
output<<obj.m;
return output;
}

void main()
{
myclass myobjct;
cout<<disp<<myobjct;
}


Above code does not run.
How to achieve above feature ?

plase help me. its urgent.
thank you.
Reply With Quote
  #2 (permalink)  
Old April 7th, 2006, 02:24 AM
Authorized User
 
Join Date: Oct 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to C@uark
Default

Not sure exactly what you are trying to acheive with your function, how ever you might do this

#include <iomanip>
#include <iostream>
using namespace std;

class myclass
{
public :
    int m,n;
    myclass(){m=10;n=12;}
}

void disp( myclass& obj )
{
    cout<<"Hello"<<endl
         <<obj.m;
    return;
}

void main()
{
    myclass myobjct();
    disp( myobjct );
    return;
}
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing references to a function demac43 Excel VBA 4 November 15th, 2006 04:23 PM
Passing an array to a Sub or Function donrafeal Access VBA 2 May 11th, 2006 09:39 AM
Passing Parameters to a function atcs2152 Ajax 4 December 22nd, 2005 09:12 AM
passing variable to function Boszky Pro PHP 2 December 15th, 2005 03:01 AM
Passing a value from one function to another PortGuy Javascript 4 October 17th, 2005 06:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.