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 8670535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:43:45+00:00 2026-06-12T18:43:45+00:00

I am having a problem in some code using type_traits from boost. It is

  • 0

I am having a problem in some code using type_traits from boost.
It is quite a complex part of the code, but I could isolate the part that gives the compilation error:

template<const size_t maxLen>
class MyString {
public:
    typedef boost::conditional<(maxLen > 0), char[maxLen+1], std::string> ObjExternal;
};

template <class T>
class APIBase {
public:
    typedef T obj_type;
    typedef typename T::ObjExternal return_type;
};

template <class T>
int edit(const T& field, const typename T::return_type& value)
{
    return 0;
}

int myFunction()
{
    APIBase<MyString<10> > b;
    char c[11];
    return edit(b, c);
}

This gives the following error:

test.cpp: In function ‘int myFunction()’:
tes.cpp:109: error: no matching function for call to ‘edit(APIBase >&, char [11])’
tes.cpp:100: note: candidates are: int edit(const T&, const typename T::return_type&) [with T = APIBase >]

However, if I change the line with the code

char c[11];

by

MyString<10>::ObjExternal c;

it works. Similarly, if instead I change the line

typedef boost::conditional<(maxLen > 0), char[maxLen+1], std::string> ObjExternal;

by

typedef char ObjExternal[maxLen+1];

it also works. I am thinking that it is a problem with boost::conditional, as it seems it is not being evaluated right. Is there a problem in my code, or there is an alternative that can be used instead of boost::conditional to have this functionality?

I am thinking about using the 2nd option, but then I could not use maxLen as 0.

  • 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-06-12T18:43:47+00:00Added an answer on June 12, 2026 at 6:43 pm

    You need to use the member typedef type provided by conditional and not the conditional type itself.

    Change:

    typedef boost::conditional<(maxLen > 0),
                               char[maxLen+1],
                               std::string> ObjExternal;
    

    to:

    typedef typename boost::conditional<(maxLen > 0),
                                        char[maxLen+1],
                                        std::string>::type ObjExternal;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with some code that used to work in PHP 4.X
I'm having a problem with some code I've written. I've had to anonymize it,
I've having this problem with some JavaScript code. I've simplified it in the error
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
I am having some problem with jsonp and jquery. This is my code -
I'm building a website and having some problem. if the HTML code is like:
I encounter some problem when using useDelimiter from the Scanner class. Scanner sc =
I'm having a problem designing some code to handle dynamic, two-dimensional data in my
I'm having a bit of an odd problem while trying to compile some code
Im having some problem with a bit of JQuery code and I don't know

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.