Templated Non-Explicit Constructor

This is a discussion on Templated Non-Explicit Constructor within the C++ Programming forums, part of the General Programming Boards category; In my program (creating a BigNum class), I have a templated non-explicit constructor. This constructor uses a ostringstream object and ...

  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136

    Templated Non-Explicit Constructor

    In my program (creating a BigNum class), I have a templated non-explicit constructor. This constructor uses a ostringstream object and then parses. If data is valid, it is stored in the BigNum object. Hence, you can use the = sign on any type with an ostream<< operator defined. I find it very useful and was wondering if there is a general opinion on whether this is bad programming practice.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I don't see any problem with it as long as the BigNum object is set to a predictable state even if the data isn't valid.
    My best code is written with the delete key.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    lol. Thanx.

    Yeah, I use -0 to denote an error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gcc can't find obvious copy constructor
    By SevenThunders in forum C++ Programming
    Replies: 13
    Last Post: 03-19-2009, 02:41 PM
  2. Interesting behavior with explicit copy constructor
    By Clairvoyant1332 in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2008, 03:19 PM
  3. A Question about explicit constructor
    By meili100 in forum C++ Programming
    Replies: 1
    Last Post: 07-08-2007, 04:08 PM
  4. Explicit constructor on strings
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 06-21-2006, 02:46 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21