LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2002, 01:21 AM   #1
guest72485
LQ Newbie
 
Registered: Jun 2002
Posts: 8

Rep: Reputation: 0
returning static


what would be the advantages of returning a static pointer.
e.g
static CSomeObject* SomeFunc1()
{
CSomeObject object = new CSomeObject;

......
......

return object;
}

static CSomeObject* SomeFunc2()
{
CSomeObject object = new CSomeObject;

......
......

return object;
}

static CSomeObject* SomeFunc3()
{
CSomeObject object = new CSomeObject;

......
......

return object;
}
 
Old 08-23-2002, 05:15 AM   #2
souvik
LQ Newbie
 
Registered: Apr 2001
Location: Calcutta, India
Posts: 16

Rep: Reputation: 0
returning a static pointer is not clear to me.
What you are trying to return is a pointer and the static key word is present to denote that the function is static function.
 
Old 08-23-2002, 07:59 AM   #3
kwigibo
Member
 
Registered: Apr 2002
Posts: 53

Rep: Reputation: 15
Assuming these are functions and not methods, you probably do not need to make the function static, you are creating the object inside the function dynamically, which means you only need to return the pointer to the object
Quote:
Code:
static CSomeObject* SomeFunc1()
{
CSomeObject object = new CSomeObject;

......
......

return object;
}
Code:
CSomeObject* SomeFunc1()
{
CSomeObject* object = new CSomeObject;  //Should object also be a pointer.
......
return object;
 
Old 08-26-2002, 12:50 AM   #4
guest72485
LQ Newbie
 
Registered: Jun 2002
Posts: 8

Original Poster
Rep: Reputation: 0
thanks for the reply my problem is solved, actually i wanted to reuse a pointer.
now i have a global declaration

static CSomeObject *object;

and in all the functions i have something like this

CSomeObject* SomeFunc1()
{
object = new CSomeObject;
return object;
}
and so on.....
making it static will ensure that it always holds a valid address in case any function fails to create the object i will always have the address of the last object.

thnks for the replies
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto Assign Multiple Static Public IP Addresses under SBC's PPPoE Static Ip system o trekgraham Linux - Networking 8 04-17-2007 10:51 AM
Is there any static ARP for static IP network? linux_lover2005 Linux - Networking 2 05-18-2005 12:01 PM
FC2 Overriding static if in favor of dhcp system set for static pkraus109 Linux - Networking 8 09-21-2004 11:13 AM
rc simlinks keep returning Shade00 Linux - Newbie 3 05-12-2004 10:48 AM
having trouble returning... jhorvath Programming 12 10-26-2002 10:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration