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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:16:28+00:00 2026-06-16T02:16:28+00:00

In that test code: #include <string> #include <iostream> using namespace std; template <typename T>

  • 0

In that test code:

#include <string>
#include <iostream>

using namespace std;

template <typename T> class Signal;

template <typename T, typename U>
class Signal<T (U)>
{
public:
  Signal<T (U)>(T (*ptr)(U))
  {
  }
};

void Print(string const& str)
{
  cout << str << endl;
}

int main(int argc, char *argv[])
{
  Signal<void (string const&)> sig = &Print;
  return 0;
}

Why do I have to write template <typename T> class Signal;?

Why do I have to specify it ?

  • 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-16T02:16:29+00:00Added an answer on June 16, 2026 at 2:16 am

    You’re creating a specialization of Signal that combines the arbitrary types T and U into the form T(U). This is put together as the specialization Signal<T(U)>: only one type is in the parameter, which why we forward-declared the Signal taking only one type T. This wouldn’t be possible without that declaration.

    Here’s a simple example:

    template <typename T> struct A;
    
    template <typename T, typename U> struct A<T(U)> {
    
    };
    
    int main() {
    
        A<void(int)> a;
    
    }
    

    The types void and int are bound to the types T and U respectively. This is combined into the type void(int) used in the primary declaration of A to specialize the class.

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

Sidebar

Related Questions

For the following code: #include<iostream> #include<vector> #include<string> using namespace std; struct Test { string
Here is the code: #include <string> #include <iostream> #include <vector> #include <algorithm> using namespace
I can't tell what's wrong with my code: #include <iostream> #include <string> using namespace
I've got the following code: #include <iostream> using namespace std; int main(int argc, char
I have the following code that tries to enumerate strings. #include <string> #include <iostream>
I have the following code: [test.cpp] #include <mcrypt.h> #include <string> #include <iostream> #include <vector>
Here is my code: //--------------------------------------------------------------------------- #pragma hdrstop #include <tchar.h> #include <string> #include <iostream> #include
This is my code #include <iostream> #include <string> #include <sys/wait.h> #include <sys/types.h> #include <unistd.h>
I'm writing test code that needs to clean up the entities it creates when
I have this test code that just saves an XML file to a folder.

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.