Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-04-2007, 07:25 PM
Coder87 Coder87 is offline
Newbie
 
Join Date: Apr 2007
Posts: 1
Rep Power: 0
Coder87 is on a distinguished road
Default classes without named instances

I want to be able to write a class that does not require a name in order to use it. For example, cin is a class but it does not require you to create a variable and then access it through that variable.

For example cin is not used like this:

int number;
class_name variable_name;

variable_name.cin >> number;


How do I do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-05-2007, 12:09 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

cin is a named instance of a class. To not use a named instance, you will have to use a named pointer to the class and use the new keyword to create the object pointed to.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2007, 01:22 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

If you want only a single object of a class, you can do like this;
Code:
class
{
	public:
		void foo()
		{
			std::cout << "Hello, World!" << std::endl;
		}
} myObject;
and then use it like this...
Code:
myObject.foo();
I don't think it's a good programming practice, but it's possible.
It's tested with GCC.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
importError: no module named _mysql ryanszeto Python 2 08-01-2007 01:08 PM
Abstract Classes CyberByte C and C++ 1 02-21-2007 07:22 PM
Data and Classes Sionofdarkness Java Help 5 08-23-2006 10:18 PM
Classes, Methods, and Objects Sionofdarkness Java Help 6 08-21-2006 01:55 PM
understanding classes Chan C# Programming 3 07-17-2006 01:19 AM


All times are GMT -5. The time now is 05:39 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads