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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:42:26+00:00 2026-06-01T13:42:26+00:00

Consider this: std::vector<int*> v(1, 0); This compiles fine with VC++10 (no warnings even at

  • 0

Consider this:

std::vector<int*> v(1, 0);

This compiles fine with VC++10 (no warnings even at max warning level). However, it doesn’t compile with llvm on mac or gcc on linux, giving an error like “assigning to int* from incompatible type const int.” I’m not looking for solutions — I know the second parameter is unnecessary or that a static_cast fixes the error.

I thought zero was implicitly convertible to any pointer type. What gives? I can do the following:

int* i = 0;
int* const& ii = 0;
const int t = 0;
i = t;

I understand that the vector constructor signature takes a const T& which when expanded for vector<int*> becomes int* const& correct? Can someone explain what is going on here, and whether the VC++ or non-VC++ compiler is correct?

  • 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-01T13:42:28+00:00Added an answer on June 1, 2026 at 1:42 pm

    It looks like g++ actually wrong here. See C++98 23.1.1/9:

    For every sequence defined in this clause and in clause 21:

    — the
    constructor template X(InputIterator f,
    InputIterator l, const Allocator& a = Allocator())

    shall have the same
    effect as: X(static_cast<typename X::size_type>(f),
    static_cast<typename X::value_type>(l), a)
    if InputIterator is an
    integral type.

    Note that InputIterator is a template parameter to the constructor, which in this case will be int for your example, and thus an integral type. The g++ library actually has specific code to handle all the cases where the type being stored in the vector is integral as well and those will all work properly. In this case, only because you used 0 would the static_cast dictated by the standard actually be legal. I tried compiling the code that the standard says should be equivalent and it compiles with g++ 4.5.

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

Sidebar

Related Questions

Consider this program: #include <map> #include <vector> typedef std::vector<int> IntVector; typedef std::map<IntVector,double> Map; void
Consider this example: #include <iostream> #include <string> #include <vector> #include <iterator> int main() {
Consider the following code snippet: std::vector<int> v; v.reserve(100); v.insert(v.end(), 100, 5); v.erase(v.begin(), v.end()); std::cout
Consider this simplified example: #include <list> typedef std::list<int> IntList; class KindaIntList { public: IntList::const_iterator
Consider this code: #include <vector> void Example() { std::vector<TCHAR*> list; TCHAR* pLine = new
Consider this: #include <iostream> using namespace std; class A{ protected: void some_function(int params) {
Consider this code: #include <iostream> using namespace std; int main() { bool lock =
Consider this line: std::wcout << Hello World!; Is it OK to pass char* or
Consider this code: #include <iostream> using namespace std; class hello{ public: void f(){ cout<<f<<endl;
Consider this example: #include <iostream> class myclass { public: void print() { std::cout <<

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.