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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:41:22+00:00 2026-06-04T03:41:22+00:00

The following header works with the commented part as expected when I call the

  • 0

The following header works with the commented part as expected when I call the function bat with no arguments:

class Test
{
 public:

  void bat(std::vector<int> k = std::vector<int>()) {}
  //void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >()) {}

};

But when I try using the cat function in the header:

class Test
{
 public:

  void bat(std::vector<int> k = std::vector<int>()) {}
  void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >()) {}

};

I get:

test.h:14: error: expected ',' or '...' before '>' token
test.h:14: error: wrong number of template arguments (1, should be 4)
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_map.h:92: error: provided for 'template<class _Key, class _Tp, class _Compare,\
 class _Alloc> class std::map'
test.h:14: error: default argument missing for parameter 2 of 'void Test::cat(std::map<int, std::vector<int, std::allocator<int> >, std::less<int>, std::all\
ocator<std::pair<const int, std::vector<int, std::allocator<int> > > > >, std::vector<int, std::allocator<int> >)'

How come? And are there easy workarounds for this? hopefully not requiring a pointer type change in the interface?

This is my full header:

#ifndef TEST_H
#define TEST_H

#include <map>
#include <vector>
#include <sstream>
#include <iostream>

class Test
{
 public:

  //void bat(std::vector<int> k = std::vector<int>()) {}
  void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >()) {}

};


#endif

so all the right includes are there. My version of GCC is terribly outdated (well not at home, ill try it at home too) – but at work it’s 4.1.2

  • 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-04T03:41:23+00:00Added an answer on June 4, 2026 at 3:41 am

    The code looks OK, but fails on gcc 4.3.4, see here, but compiles fine with 4.6 onwards (I haven’t tested 4.4 or 4.5). So it looks like the workaround is to use a newer gcc.

    #include <map>
    #include <vector>
    
    class Test
    {
     public:
    
      void bat(std::vector<int> k = std::vector<int>()) {}
      void cat(std::map<int, std::vector<int> > k = std::map<int, std::vector<int> >
    ()) {}
    
    };
    
    int main() {
    
    }
    

    Concerning default parameters, it may be an idea to drop them altogether:

    class Test {
     public:
    
      void bat(std::vector<int> k) {}
      void bat() {}
      void cat(std::map<int, std::vector<int> > k) {}
      void cat() {}
    };
    

    otherwise, you couple the default parameters to the interface, meaning you cannot change them without requiring re-compilation of all client code.

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

Sidebar

Related Questions

I have the following C++-class: // Header-File class A { public: A(); private: B
I'm making an ajax call to a rest API and specified the following header
I have the following: in header: <script type=text/JavaScript> $(document).ready(function() { $(.modal).fancybox({ // for modals
In the following model: class header(models.Model): title = models.CharField(max_length = 255) created_by = models.CharField(max_length
in header file I have defined the following function #ifndef OS_H #define OS_H #include
So, I have a file that sends the following: header(Pragma: public); header(Expires: 0); header(Cache-Control:
So I have a base class with the following header file: #ifndef ODESolver_H #define
I have an ant script with the following header: <project name=Simple ActiveJDBC Example default=clean
I'm trying to load a hypothetical plugin with the following header: #ifndef _DLL_H_ #define
Is the following From header incorect? // To send HTML mail, the Content-type header

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.