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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:51:29+00:00 2026-06-05T18:51:29+00:00

I am trying to impose some sort of semantic logic for the default values

  • 0

I am trying to impose some sort of semantic logic for the default values of method (or constructor) parameters. Here is what I have tried:

#include <iostream>
#include <vector>
class Test
{
public:
    static const std::vector<int> staticVector;
    Test (const std::vector<int> &x = Test::staticVector) {}
};

int main ()
{
    Test x;

    return 0;
}

Although staticVector is rather redundant, since C++ does not allow NULL to be passed as an instance of std::vector, I wish to avoid making redundant calls to the constructor std::vector(), so I came up with this approach…

Unfortunately, when I try to compile it, the linker throws this error:

error LNK2001: unresolved external symbol "public: static class std::vector<int,class std::allocator<int> > const Test::staticVector" (?staticVector@Test@@2V?$vector@HV?$allocator@H@std@@@std@@B)

What am I missing here?

  • 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-05T18:51:31+00:00Added an answer on June 5, 2026 at 6:51 pm

    This actually has nothing to do with the use of a default parameter. Instead, it’s a side-effect of how static variables work in C++.

    Having a static object in a C++ class is a two-step process. First, you have to declare the static object, which you’ve done, but then you have to actually define it somewhere so C++ knows which translation unit should contain the one definition of that static object. You can do this by writing

    const std::vector<int> Test::staticVector;
    

    somewhere in your C++ source file outside of the class. This tells C++ that your source file contains the definition of this object, which should resolve the linker error.

    If you have several different source files and not just one, then you should put this line in the source file for the Test class rather than in the header.

    Hope this helps!

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

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying to impose a @Oneto7 association. I'd have imagined an attribute that specifies
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
Trying to parse an HTML document and extract some elements (any links to text
Trying to avoid the SomethingManager trap here... Let's say I'm going to write a
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
I have some old C 32 Bit DLLs that are using Oracle's Pro C
I have a Visual Studio package that does some of its work by starting
I am trying to get some locations in New York using FourSquare API using

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.