GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Nov-2004, 05:46
Poolan Poolan is offline
New Member
 
Join Date: Oct 2004
Posts: 19
Poolan is on a distinguished road

How can we trap errors in Constructors (C++)


How can we trap errors in constructors as constructors will not retrun any values.

And one more question.

What do you mean by the canonical form of a class

Poolan
  #2  
Old 18-Nov-2004, 12:19
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
You could pass a reference parameter to the constructor and use that to notify you of an error. I'm assuming that you are doing File I/O or dynamic allocation, because normally, the constructor is used to do simple tasks like zeroing out all the variables in the class and such... anyhow, as for the canonical form of a class, I would start by looking up the word canonical.
__________________
-Aaron
  #3  
Old 18-Nov-2004, 12:21
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
This might be it...

Conforming to orthodox or well-established rules or patterns, as of procedure.

This probably means using the class to represent a stack, queue, or linked list. Those are just examples of classes with well established rules and patterns.
__________________
-Aaron
  #4  
Old 18-Nov-2004, 15:21
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Poolan
How can we trap errors in constructors as constructors will not retrun any values.

And one more question.

What do you mean by the canonical form of a class

Poolan

1. You can throw exceptions.

2. Maybe this should be: "What does the instructor mean by the canonical form of a class?" The word "canonical" has been used in textbooks to mean a boilerplate beginning of all user-defined classes that corresponds to the most basic built-in classes:

From http://cpptips.hyperformix.com/cpptips/orth_can_class
Quote:
As a rule of thumb I suggest that programmers should "always"
*explicitly* {uh-oh, I can hear the flames already} define the
following four member functions for "each and every" C++ class:

typically:

default constructor Foo::Foo();
copy constructor taking a const ref Foo::Foo(const Foo&);
[almost always virtual] destructor virtual Foo::~Foo();
assignment operator const Foo& Foo:perator=(const Foo&);

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

[ NOTE: this is referred to as the orthodox canonical form in "Advanced
C++ Programming Styles and Idioms", by James Coplien. - ed]

(You could have looked it up yourself, maybe?)

Regards,

Dave
  #5  
Old 19-Nov-2004, 03:01
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
I also think that throwing exceptions is DEFINETELY the way to go about this; if your compiler doesn't have a built in throw-catch or wathever mechanism, you could try the stl (in case it supports that) for its outstanding implementation

Another link regarding the canonical form: Hedlund.

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #6  
Old 19-Nov-2004, 03:49
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
You guys are just too advanced for me. I would've suggested throwing exceptions, but I haven't learned how to do it yet.
__________________
-Aaron
  #7  
Old 19-Nov-2004, 08:41
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by LuciWiz

...

Another link regarding the canonical form: Hedlund.

Kind regards,
Luci

That's the reason I worded my #2 response the way I did. This is modestly called "Hedlund's Canonical Form" in class notes by an instructor named Hedlund. He does give a textbook reference. My advice to the original poster is to check his textbook or class notes for his instructor's take on "canonical" in this context.

Regards,

Dave
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help to debug complier errors nkhambal C Programming Language 3 04-Oct-2004 09:26
Wierd errors (again) crystalattice C++ Forum 3 15-Aug-2004 21:02
Subversive fun with a bot trap jrobbio MySQL / PHP Forum 9 06-Jun-2004 00:54
Error C2143: syntax error : missing ';' before 'type' small_ticket C Programming Language 6 15-May-2004 12:59
Can somebody look at this and point out any errors to me soulfly C Programming Language 7 31-Mar-2004 10:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:10.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.