Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:10:15+00:00 2026-05-30T03:10:15+00:00

I ran into this issue quite a few times. Let’s say I have a

  • 0

I ran into this issue quite a few times. Let’s say I have a method:

template <typename T>
bool Foo(T* param)
{
  //...
}

If I pass a non-pointer, Visual Studio gives me the error: could not deduce template argument for 'const T *' but since the code is heavily templated, there is a ton of garbage attached to it (I say garbage because it is not related to the error… i.e. namespaces and template types etc.). Yes, I can tell what is wrong by looking at the message, but it takes that much longer and I think people can relate how that wastes time in the long run.

So I thought I will provide a overload and give a static assertion:

template <typename T>
bool Foo(T param)
{
  STATIC_ASSERT_FORCE(Function_does_not_take_a_non_pointer_argument);
}

This works nicely and I get a nice, clear error message. This function is placed just before the definition of the ‘correct’ function and it becomes immediately clear what I (or whoever is using my code) did wrong and what to do to correct it (that is, call the correct overload).

But that obviously pollutes the method list. Is there any other way to output a better error message?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:10:17+00:00Added an answer on May 30, 2026 at 3:10 am

    Instead of only accepting pointers, you could modify your function to accept any type:

    template <typename T>
    bool Foo(T param)
    {
      //...
    }
    

    In the body, just assume that param is a pointer. If it isn’t, the compiler will complain about operator-> or operator* being undefined for type T, and hopefully it’ll also tell you what T‘s concrete type is.

    I’m not sure if this really helps the clarity of your error messages. But it comes with a bonus: your function can suddenly be applied to other pointer-like types as well!


    Edit: there might be some SFINAE static-assertion trickery to actually verify that the operators you want are implemented for T and give a clear error if they’re not. Maybe someone else will chime in with a solution for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone ran into this issue? We have a mobile site that can't use
I have run into this issue too many times and need this to be
I ran into this interesting issue today. I have a button on a wpf
I ran into this issue while testing a rails app deployed to two different
I just ran into this issue while making a GET request to a node.js
I've ran into trouble with SOAP, I've never had this issue before and can't
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I ran into this situation today. I have an object which I'm testing for
I ran into this issue when trying to add a CMFCMenuButton to an existing
I ran into this issue on accident while debugging a faulty string trim function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.