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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:34:43+00:00 2026-06-10T21:34:43+00:00

I am having a problem calling a template function with two template arguments. I

  • 0

I am having a problem calling a template function with two template arguments.

I have a class and the class accepts objects of two different types. I don’t know the types yet, so I left them as template parameters. I then store the objects in wrapper classes. In the end I want to be able to call a templated function with two template arguments, that takes my two objects. But I am perplexed at how to do this.

Here is a stripped down version of the code to explain my problem.

template<typename A, typename B>
void someTemplateFunction(A a, B b);


class Problem
{
  private:
    class WrapperA
    {
      public:
        virtual void doSomething() = 0;
    };

    template<typename A>
    class ConcreteWrapperA : public wrapperA
    {
      private:
        A a;
      public:
        ConcreteWrapperB(A b_) : a(a_) {}
        virtual void doSomething();
    };

    class WrapperB
    {
      public:
        virtual void doSomething() = 0;
    };

    template<typename B>
    class ConcreteWrapperB : public wrapperB
    {
      private:
        B b;
      public:
        ConcreteWrapperB(B b_) : b(b_) {}
        virtual void doSomething();
    };

    WrapperA *a;
    WrapperB *b;

  public:

    template<typename A>
    void setA(A a)
    {
      a = new ConcreteWrapperA<A>(a);
    }

    template<typename B>
    void setB(B b)
    {
      a = new ConcreteWrapperB<B>(b);
    }

    void call_someTemplateFunction(); // ??????? How do i do this?
};
  • 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-10T21:34:45+00:00Added an answer on June 10, 2026 at 9:34 pm

    The problem is that you’ve type-erased both types A and B separately, so there’s nowhere in the translation of your code that both types A and B are known.

    If you can write a single function template<typename A, typename B> void set(A, B) then you could capture the pair type <A, B> at that point.

    Alternatively, would it be possible for someTemplateFunction to operate without knowing both types A and B at the same time?


    This is an issue fundamental to the design of C++ as a single-pass, separate compilation language.

    Suppose that your program has three compilation units; A.cpp calls setA with a range of types T[A], B.cpp calls setB with another range of types T[B], and C.cpp owns the Problem object and wants to call someTemplateFunction. Then there’s no time during compilation when the compiler knows both the range of types in A.cpp and the range of types in B.cpp, so it can’t instantiate someTemplateFunction with the appropriate cross-product T[A] x T[B].

    • 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 calling a function in a different class in QT
I'm having a problem in C++ with calling a function of a derived class
I am having a problem with calling a ext function in odata4j in android
I am having a problem while calling overloaded C# function through jquery post method.
I'm having a problem in calling a function that returns a result, from another
I'm having a (minor) problem here. I'm calling a named template and am assigning
I am having a problem of calling the user defined JS function after I
Im having a problem with using a variable as the class name when calling
I'm having a weird problem, I have the following code in my page.php template
I am having a problem calling a model property from my view. I may

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.