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

  • Home
  • SEARCH
  • 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 8565197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:22:15+00:00 2026-06-11T17:22:15+00:00

I’m trying to write a fixed point arithmetic class where point position and underlying

  • 0

I’m trying to write a fixed point arithmetic class where point position and underlying type are templates

template <int P, typename T>
class basic_fixedpoint{
    //stuff
};

I also want to expose a single templated implicit constructor that is then specialized for various types

//inside basic_fixedpoint
    template <typename U>
    basic_fixedpoint(const U& arg);

Elsewhere I will implement specializations for int, float, double, etc. However, I also want to provide a generic specialization for any type of basic_fixedpoint with different P and T. How can I do this as a templated template specialization?

template <int P, typename T> //for the class whose constructor i specialize
template <int OP, typename OT> //for the parameters of the argument
basic_fixedpoint<P, T>::basic_fixedpoint<basic_fixedpoint<OP, OT> >(const basic_fixedpoint<OP, OT>& arg)
    : /*init things here*/ {} // this fails

I’m trying to avoid overloading the constructor so as to present a single interface in the header, telling the user “This class will cleanly construct itself from whatever type you give it, or it will fail to compile and give you an incomprehensible paragraph long error message”

As a sub question: This class also implements the basic operator int(), operator float(), operator double() conversions, and also overloaded arithmetic operators and math functions are provided. Naturally, whenever I try to invoke anything with this class, the call is ambiguous because every possibility is available.

How can I keep this class fully flexible, but still allow pain-free unambiguous overloaded function calls that behave properly (rather than always converting my class to a double and back)?

  • 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-11T17:22:16+00:00Added an answer on June 11, 2026 at 5:22 pm

    I think you may want to reconsider what you really want. Implicit conversions are not always a good idea (they are a bad idea more often than not) and a class that can be implicitly convertible to and from the same types is always a bad idea (it will cause ambiguity errors whenever you use that class and the convertible to/from type together as it could go both ways.

    You should go back to the design board and decide what needs to be implicit and what can be named or explicit conversions.

    Besides that, and regarding your particular question, you cannot specialize that constructor. Functions (and constructors among them) can only be fully specialized, and in particular you cannot specialize a template function that is a member of a template class without also fully specializing the class template. I.e. you can specialize:

    basic_fixedpoint<5,int>::basic_fixed_point<int>(int)
    

    but you cannot specialize:

    template <int N, typename T>
    basic_fixed_point<N,T>::basic_fixed_point<int>(int)
    

    As N and T are not bound in that specialization.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.