Thread: Template Trouble - Brainache Please Help

  1. #1
    Registered User SpaceCadet's Avatar
    Join Date
    Oct 2006
    Posts
    23

    Unhappy Template Trouble - Brainache Please Help

    I am working on replacing multiple overrides of a function within a legacy code base (all of which are virtual), with a single template signature.

    My template function is as follows:

    Code:
    template <typename T1, typename T2> void fn_data_access_base::var_fld_add(T1 nam, T2 val)
    {
        // Set the db field up
        sis_db_fld tmp_sis_db_fld( val, nam );
    
    
        assert( !selector_impl_ptr_ ||
               ( selector_impl_ptr_ &&
                 selector_impl_ptr_->fld_find( tmp_sis_db_fld ) ) );
    
        // Update the field
        input_fld_rpl_or_append( tmp_sis_db_fld );
    }
    The Sun compiler complains as follows...

    Code:
    "/vobs/VDPS_Dev/online/base_src/Server/fn/fndal/dabase.cpp", line 1610: Error: Overloading ambiguity between "sis_db_fld::sis_db_fld(const bool, const sis_c_str&)" and "sis_db_fld::sis_db_fld(const char, const sis_c_str&)".
    "/vobs/VDPS_Dev/online/base_src/Server/fn/fndal/fndbase.cpp", line 75:     Where: While instantiating "fn_data_access_base::var_fld_add<const char*, int>(const char*, int)".
    "/vobs/VDPS_Dev/online/base_src/Server/fn/fndal/fndbase.cpp", line 75:     Where: Instantiated from fn_data_abstract_base::var_fld_add<const char*, int>(const char*, int).
    "/vobs/VDPS_Dev/online/base_src/Server/fn/fnelog/elog.cpp", line 268:     Where: Instantiated from non-template code.
    1 Error(s) and 1 Warning(s) detected.
    *** Error code 1
    It is my understanding that the compiler ought to be able to distinguish between all native types within the template when calling the sis_db_fld constructor, thus I should not experience ambiguity.

    I have tried making the sis_db_fld constructors that match the ambiguous signatures 'explicit' but this keywork has no effect when construction is from within a template.

    I have tried retaining non template versions of var_fld_add that use the specific types identified as ambiguous. Again this does not work?

    I do not understand why it fails to do so?


    Please help. I have hit a brick wall with this one!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Does a sis_db_fld constructor with the signature (int, const sis_c_str &) exist? Apparently not: the compiler tries to find an alternative, but can't decide between the bool and the char variant.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User SpaceCadet's Avatar
    Join Date
    Oct 2006
    Posts
    23
    Yes it does. However, an act of unbelievable programming is at the root of this.

    Too heavy to explain. Thanks for you help, I think I'm on to it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM