codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  why constructors don`t return any value  vector at 19:42 on Sunday, September 11, 2005
 

can anyone tell me why constructors don't return any value

  Re: why constructors don`t return any value  geTTysburg at 18:23 on Friday, October 14, 2005
 

There's would be no way to read a return value if a contructor was allowed to return a value.

A constructor is either implicitly called when you declare a static class object, or called as a result of "new" operatation. In either case, there's no way to receive a return value.

If you need to return a value, you should consider passing in a pointer to a variable which will receive the result, and assigning the value before you exit the contructor. This method will only work for dynamically created objects.


Example:

class MyClass{

public:
MyClass(int *ReturnValue);
~MyClass();

//Other class methods and properties
....
....
....
};

MyClass::MyClass(int *ReturnValue)
{
//Do some stuff
....
....
....
....

*ReturnValue = <some value>
}


//in main code
MyClass *A;
int Result;

A = new MyClass(&Result);










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Database Search
•  Access https in http page
•  IE page Redirect
•  Re: Javascript problem with document.write and accented characters
•  Re: sorting and Linked list
•  Re: need help linked list
•  Re: Help with arrays
•  Re: Reading from a file
•  Re: Why Use Method?


Recent Articles
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net
Creating CSS Buttons


© Copyright codetoad.com 2001-2006