Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-23-2007, 11:57 AM   #1 (permalink)
destin
Java Junkie
 
destin's Avatar
 
Join Date: Mar 2005
Posts: 40
destin is on a distinguished road
Functions that accept all types?

In C++, is it possible to have a function that accepts all types?

Basically, I want to override the left-shift operator so that I can do the following.
Code:
myVar << a << b << moreStuff << "blah" << endl;
Is there a way I can accomplish this so that I don't have to override dozens of operator functions?

I would like to do something like this:
Code:
MyClass& MyClass::operator<<(??? var)
{
  stringstream stream;
  stream << var;
  // do something with stream.str()
  return *this;
}
Thanks in advance.
destin is offline   Reply With Quote
Old 08-24-2007, 08:41 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Learn the ways of templates and operator overloaden.
An exhaustive tutorial is on this net (see on the left side, c++, Operator Overloading).
Are function templates any good to you?
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inheritance and functions... Aniviel833 Standard C, C++ 20 09-18-2005 01:18 PM
Functions available using MinGW.... Surveyor Standard C, C++ 2 04-05-2005 05:52 AM
dBase functions in PC based PHP? Wysocki PHP 1 02-11-2005 11:49 AM


All times are GMT -8. The time now is 08:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting