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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:31:56+00:00 2026-05-21T03:31:56+00:00

I have an odd problem with C++ templates and I don’t understand why the

  • 0

I have an odd problem with C++ templates and I don’t understand why the following code is not working:

#include <iostream>

template <typename A, typename B>
class TypePair {
public:
    typedef A First;
    typedef B Second;
};


template <typename P>
class Foo {
    public:
        Foo(P::First f, P::Second) {
            std::cout
                << "first = " << f << std::endl
                << "second = " << s << std::endl;
        }
};


int main(int argc, char **argv) {
    Foo<TypePair<int, double> > foo(42, 23.0);

    return 0;
}

The code produces the following errors:

$ g++ templates.cpp -o templates
templates.cpp:14: error: expected ‘)’ before ‘f’
templates.cpp: In function ‘int main(int, char**)’:
templates.cpp:23: error: no matching function for call to ‘Foo<TypePair<int, double> >::Foo(int, double)’
templates.cpp:12: note: candidates are: Foo<TypePair<int, double> >::Foo()
templates.cpp:12: note:                 Foo<TypePair<int, double> >::Foo(const Foo<TypePair<int, double> >&)

For me the code this looks totally fine, but g++ obviously has its own opinion ^^ Any ideas?

Sebastian

  • 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-05-21T03:31:56+00:00Added an answer on May 21, 2026 at 3:31 am

    Use

    Foo(typename P::First f, typename P::Second s)
    

    Since P is a template parameter, P::First and P::Second are dependent names, so you have to explicitly specify they are typenames, not, for example, static data members. See this for details

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

Sidebar

Related Questions

I have the odd problem that I am not able to open the properties
I have a rather odd problem: I need to maintain a chunk of code
I have an odd problem...I'm using a documentation generator which generates a lot of
I have an odd problem in VS2008 running unit tests. When I run the
I recently encountered an odd problem with RSACryptoServiceProvider.VerifyHash . I have a web application
I am having a really odd problem with Flash CS4. I have a MovieClip
I have an odd edge case right now in that a response code from
I have an odd problem with Django. I have a set of objects that
I've got an odd problem with a WPF Calendar control. I have modified the
I have an odd problem. I have a number of C# apps that utilize

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.