Thread: Type/value mismatch while passing type as parameter to function

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    17

    Type/value mismatch while passing type as parameter to function

    Inside a function x_gradient(), I declare a type dst_channel_t like so:

    Code:
    typedef typename channel_type<DstView>::type dst_channel_t;
    I'm trying to pass this type as a parameter to a another function (x_gradient_par()) which runs in a thread like so:

    Code:
    mythreads[i] = std::thread(&x_gradient_par<const SrcView&, const DstView&>, src, dst, dst_channel_t, start, end);
    This is what function x_gradient_par() looks like:

    Code:
    template <typename SrcView, typename DstView>
    void x_gradient_par(const SrcView& src, const DstView& dst, const typename channel_type<DstView>::type dst_channel_t, int start, int end) {
        //typedef typename channel_type<DstView>::type dst_channel_t; //I was previously trying to define the type here, but it would always generate an 'invalid use of incomplete type..' error.
    
        for (int y = start; y < end; ++y)
        {
            typename SrcView::x_iterator src_it = src.row_begin(y);
            typename DstView::x_iterator dst_it = dst.row_begin(y);
    
            for (int x = 1; x < src.width() - 1; ++x)
            {
                static_transform(src_it[x - 1], src_it[x + 1], dst_it[x],
                                 halfdiff_cast_channels<dst_channel_t>());
            }
        }
    }
    
    Any hints?

    I've attached both the header file and a log file that contains the errors being produced.

    x_gradient_par.h
    log.txt

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    836
    What happens if you add this to x_gradient_par.h?
    Code:
    #include <boost/gil/gil_all.hpp>
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  3. #3
    Registered User
    Join Date
    Apr 2016
    Posts
    17
    No difference. I actually don't think there would be anything wrong with the includes since this is an assignment and that part at least was provided by the lecturer.

  4. #4
    Registered User
    Join Date
    Apr 2016
    Posts
    17
    It turns out I needed to state the type when calling the function and I wan't doing that. What I was doing was attempt to pass a type as a parameter to the function.
    Here's what changed:

    When calling the function, I state all types used in the template and no longer pass the type dst_channel_t as a parameter.
    Code:
    mythreads[i] = std::thread(&x_gradient_par<const SrcView&, const DstView&, const dst_channel_t&>, src, dst, start, end);
    Similarly with the function declaration.
    Code:
    template <typename SrcView, typename DstView, typename dst_channel_t> 
    void x_gradient_par(const SrcView& src, const DstView& dst, int start, int end) 
    {
        ...
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer type mismatch (enabled by default) warning.
    By Satya in forum C Programming
    Replies: 15
    Last Post: 07-09-2015, 12:35 PM
  2. asmtest.c:16: Error: operand type mismatch for `jmp'
    By Jacob Dahlen in forum C Programming
    Replies: 10
    Last Post: 08-30-2013, 12:21 PM
  3. Type Mismatch Error
    By sanks85 in forum C Programming
    Replies: 1
    Last Post: 04-01-2013, 01:58 AM
  4. Data type mismatch in criteria expression ERROR
    By Aga^^ in forum C# Programming
    Replies: 2
    Last Post: 02-11-2009, 01:21 AM
  5. Type mismatch warning
    By Opel_Corsa in forum C Programming
    Replies: 5
    Last Post: 10-11-2006, 10:34 AM

Tags for this Thread