Thread: Could not deduce type for T

  1. #1
    Join Date
    Oct 2007
    Inside my computer

    Could not deduce type for T

    This simple code snippet fails to work as expected for some reason, instead requiring me to explicitly specify type for T (for the function call foo):

    template<typename T>
    void foo(typename Stuff::mpl::ArgumentHelper<T>::type Arg)
    	cout << Stuff::mpl::type_name<Stuff::mpl::add_const<typename Stuff::mpl::ArgumentHelper<T>::const_type>::type>::name << endl;
    	Arg.x = 5;
    class A { public: int x; };
    namespace mpl = Stuff::mpl;
    int main()
    	A a;
    	a.x = 0;
    	cout << a.x << endl;
    Does anyone know why?
    ArgumentHelper is defined as follows:

    		namespace detail
    			template<typename T, bool IsFundamental> struct ArgumentHelper { typedef T type; typedef T const_type; };
    			template<typename T> struct ArgumentHelper<T, false> 
    				typedef typename boost::add_reference<T>::type type;
    				typedef typename Stuff::mpl::add_const<type>::type const_type;
    		template<typename T> struct ArgumentHelper
    			typedef typename boost::remove_reference<typename boost::remove_const<T>::type>::type raw_type;
    			typedef typename detail::ArgumentHelper<T, boost::is_fundamental<raw_type>::value>::type type;
    			typedef typename detail::ArgumentHelper<T, boost::is_fundamental<raw_type>::value>::const_type const_type;
    Explanations are greatly appreciated O_O
    EDIT: And how to work around it in a good way, if possible. Otherwise the whole thing is doomed.
    Last edited by Elysia; 07-14-2008 at 07:39 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    as far as I know, there is know way to specify a typename as a parameter. I asked a similar question in the past (I can't seem to find), but basically it's because it would force the compiler to instantiate a template in order to do the lookup...I'm sure someone around here can give a more lucid explanation of course.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 08:59 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Compiler "Warnings"
    By Jeremy G in forum A Brief History of
    Replies: 24
    Last Post: 04-24-2005, 02:09 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 01:22 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM
Website Security Test