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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:18:26+00:00 2026-06-09T05:18:26+00:00

Sorry could not find a better title for my question. Basically what I noticed

  • 0

Sorry could not find a better title for my question. Basically what I noticed was the following compiles fine:

#include <vector>

void foo();

int main () {
    foo();
    return 0;
}

namespace{
struct point {
        double x, y;
    };
}

void foo(){       
    std::vector<point> p;
}

whereas compiler complains about the following:

#include <vector>

void foo();

int main () {
    foo();
    return 0;
}

void foo(){
    struct point {
        double x, y;
    };       
    std::vector<point> p;
}

// g++ output:
a.cpp: In function ‘void foo()’:
a.cpp:14: error: template argument for ‘template<class _Tp> class std::allocator’ uses local type ‘foo()::point’
a.cpp:14: error:   trying to instantiate ‘template<class _Tp> class std::allocator’
a.cpp:14: error: template argument 2 is invalid
a.cpp:14: error: invalid type in declaration before ‘;’ token

I want to know what is wrong with the second approach? Isn’t struct point completely defined at the point of creating a new std::vector<point> object?

  • 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-09T05:18:28+00:00Added an answer on June 9, 2026 at 5:18 am

    This is due to a limitation in C++03 (now lifted in C++11), that simply forbids the use of local types (i.e. types defined in function bodies) as template arguments.

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

Sidebar

Related Questions

Sorry i could not find a proper title to this question. I have generated
sorry if dumb but could not find an answer. #include <iostream> using namespace std;
I am sorry to ask this trivial question but I could not find a
Sorry I could not find the appropriate title Here is my problem I am
I'm sorry to ask such a basic question but I could not find a
sorry for my rather general question, but I could not find a definite answer
I'm sorry if such a question is asked before but i could not find
Sorry if this has already been answered but I could not find it here.
I could be not more sorry guys - the question was a very wrong
I'm new to jquery, and sorry if this question is asked before (could find

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.