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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:37:08+00:00 2026-06-17T21:37:08+00:00

I have some constants named like this: template<int n> class usart { private: usart();

  • 0

I have some constants named like this:

template<int n> class usart {
private:
    usart();
public:
    enum class tx {};
    enum class rx {};
    enum class ck {};
};

template<> class usart<1> {
public:
    enum class tx { A9  = gpio::A9,  C4 = gpio::C4 };
    enum class rx { A10 = gpio::A10, C5 = gpio::C5 };
    enum class ck { A8  = gpio::A8 };
};

// two more of these

where gpio is just a simple integer enum.

I’d like to enforce some type safety on my class in another file:

class USART {
public:
    template<int N>
    USART(typename usart<N>::tx pin_tx, typename usart<N>::rx pin_rx) {
        //This signature enforces correct pins with types, doesn't it?
    }
};

However, when I use this with

USART us = USART(usart<1>::tx::A9, usart<1>::rx::A10);


I get the error

error: expected ')' before 'pin_tx'

Why is this syntax illegal?
EDIT: typename

This now gives me this error when I try and instantiate the class:

error: no matching function for call to 'USART::USART(usart<1>::tx, usart<1>::rx)'
note: template<int N> USART::USART(typename usart<N>::tx, typename usart<N>::rx)
note:   template argument deduction/substitution failed:
note:   couldn't deduce template parameter 'N'
  • 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-17T21:37:09+00:00Added an answer on June 17, 2026 at 9:37 pm

    The template parameters used in the function arguments are not deducible because the the arguments are of dependent types.

    “But that’s silly!” you would say; “It is obvious that N is 1! Why can’t the compiler have the smarts to deduce that?”

    Consider the following:

    template<> class usart<4321> {
    public:
        typedef usart<1>::tx tx;
        typedef usart<1>::rx rx;
        typedef usart<1>::ck ck;
    };
    

    Should N be 1 or 4321? After all, usart<4321>::tx and usart<1>::tx are the same type.

    The compiler cannot know what N should be without checking that only one instantiation of usart has that exact type as the tx member. This would either require too many instantiations or way too complex logic to prove that no instantiation would result in that in the general case. Sure, it might be simple to implement something for this particular case, but that isn’t terribly useful for all other cases. The C++ committee simply decided to not require this of compiler writers.

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

Sidebar

Related Questions

I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a ViewModel like this: public class MyViewModel { [Display(Name = One_Name, ResourceType
I have a C++ class implementation file which has some constants. The constants appear
I have some constants in JavaScript that I'd like to reuse in several files
I have a basic text template engine that uses a syntax like this: foo
I've never seen anything like this. File structure: somefolder/base.php includes/stuff.php includes/constants.php base.php: <?php require(../includes/stuff.php);
I have a common NAnt script (containing some common targets and constants) that I
I have a code pattern which translates one integer to another. Just like this:
We have an Yii-based PHP application which does some generic actions (like Share with
Are their any feature exist something like data template. i have a js file

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.