473,230 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Doubt on Constructors

Hi,

in the below statement :

class A {
int *i;
A(){

};

main()
{
A* a=new A();
}

if suppose the constructor A() will create a socket and while doing
that it fails and we didnt catch the exception then will the variable
"a" gets the memory..??

Jul 12 '06 #1
6 1459
edu.mvk <ed*****@gmail.comwrote:
class A {
public:
int *i;
A(){
}

Do not type in your news reader. Copy and paste from the source you
compiled (or tried to). People might want to try to compile your code
without having to fix dozens of errors first.
>
};

main()
int main ()
{
A* a=new A();
delete a;
}

if suppose the constructor A() will create a socket and while doing
that it fails and we didnt catch the exception then will the variable
"a" gets the memory..??
When an exception is thrown, that you do not catch, any code after
the exception was thrown will not be executed. That is, 'a' will never
point to anything meaningful, if the ctor of A throws.

hth
--
jb

(reply address in rot13, unscramble first)
Jul 12 '06 #2
In article <11**********************@h48g2000cwc.googlegroups .com>,
"edu.mvk" <ed*****@gmail.comwrote:
Hi,

in the below statement :

class A {
int *i;
A(){

};

main()
{
A* a=new A();
}

if suppose the constructor A() will create a socket and while doing
that it fails and we didnt catch the exception then will the variable
"a" gets the memory..??
Nothing will get the memory. The memory will be given back to the
"system". Unless, of course, someone re-implemented operator new and did
it incorrectly.
Jul 12 '06 #3
Jakob Bieling wrote:
Do not type in your news reader. Copy and paste from the source you
compiled (or tried to). People might want to try to compile your code
without having to fix dozens of errors first.
Further, they will point out all the errors in your code without
answering your real question. By the way, the class A() is
can't be instantiated via new due the private default constructor.
Jul 12 '06 #4

Daniel T. wrote:
In article <11**********************@h48g2000cwc.googlegroups .com>,
"edu.mvk" <ed*****@gmail.comwrote:
Hi,

in the below statement :

class A {
int *i;
A(){

};

main()
{
A* a=new A();
}

if suppose the constructor A() will create a socket and while doing
that it fails and we didnt catch the exception then will the variable
"a" gets the memory..??

Nothing will get the memory. The memory will be given back to the
"system". Unless, of course, someone re-implemented operator new and did
it incorrectly.
Thx for ur answer Daniel,

i have a small doubt..

whats the situation if i didnt throw any exception from that
constructor and the socket creation has failed because of some
reason..?? ( we didnt use the exception handling for that failure )

will the object be created or not ?

Jul 12 '06 #5

"edu.mvk" <ed*****@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>
Daniel T. wrote:
>In article <11**********************@h48g2000cwc.googlegroups .com>,
"edu.mvk" <ed*****@gmail.comwrote:
Hi,

in the below statement :

class A {
int *i;
A(){

};

main()
{
A* a=new A();
}

if suppose the constructor A() will create a socket and while doing
that it fails and we didnt catch the exception then will the variable
"a" gets the memory..??

Nothing will get the memory. The memory will be given back to the
"system". Unless, of course, someone re-implemented operator new and did
it incorrectly.

Thx for ur answer Daniel,
Please use complete words, like "Thanks for your...". This isn't a
text-messager, or instant messenger. A lot of people here are not native
English speakers, and have a hard enough time with English, without having
to also interpret "IM-speak".
i have a small doubt..

whats the situation if i didnt throw any exception from that
constructor and the socket creation has failed because of some
reason..?? ( we didnt use the exception handling for that failure )
If the creation of the socket fails, and no exception is thrown (either by
you or by the call to create the socket itself), then your object will be
created normally. But obviously you'll have problems later trying to use
the socket, won't you? :-)

Of course, we don't know anything about how you're attempting to create the
socket or what it does when it fails to create properly, so we can't tell
you what would happen if it "failed because of some reason".

-Howard


Jul 12 '06 #6
In article <11**********************@p79g2000cwp.googlegroups .com>,
"edu.mvk" <ed*****@gmail.comwrote:
Daniel T. wrote:
In article <11**********************@h48g2000cwc.googlegroups .com>,
"edu.mvk" <ed*****@gmail.comwrote:
Hi,
>
in the below statement :
>
class A {
int *i;
A(){
>
};
>
main()
{
A* a=new A();
}
>
if suppose the constructor A() will create a socket and while doing
that it fails and we didnt catch the exception then will the variable
"a" gets the memory..??
Nothing will get the memory. The memory will be given back to the
"system". Unless, of course, someone re-implemented operator new and did
it incorrectly.

Thx for ur answer Daniel,

i have a small doubt..

whats the situation if i didnt throw any exception from that
constructor and the socket creation has failed because of some
reason..?? ( we didnt use the exception handling for that failure )

will the object be created or not ?
Yes it will.
Jul 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rajesh Garg | last post by:
Can we have private constructors and destructors? IF yes what is the use of such constructors or destructors.....in the sense where can these be implemented in a system................. I have...
42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
6
by: Stephen Martinelli | last post by:
thanks for the help...just one more question.... can a class have more then two parameterized constructors?..i would like to be able to instanciate the class with a different number of...
10
by: John | last post by:
Trying to find out what is essential / optional, I made an extremely simple Class and Module combination to add two numbers. (see below) It appears that an empty constructor is needed n order to...
3
by: John | last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far. I am now able to better define the question! After adding more console printout lines to CSum, I tried all...
22
by: Peter Morris [Droopy eyes software] | last post by:
Look at these two classes public class Test { public readonly string Name; public Test(string name)
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.