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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:24:50+00:00 2026-05-13T11:24:50+00:00

Consider this void f(vector<const T*>& p) { } int main() { vector<T*> nonConstVec; f(nonConstVec);

  • 0

Consider this

 void f(vector<const T*>& p)
 {
 }
 int main()
 { 
  vector<T*> nonConstVec;
  f(nonConstVec);
 }

The following does not compile.The thing is that vector<T*> can not be converted to vector <const T*> , and that seems illogically to me , because there exists implicit conversion from T* to const T*. Why is this ?

vector<const T*> can not be converted to vector <T*> too, but that is expected because const T* can not be converted implicitly to T*.

  • 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-13T11:24:50+00:00Added an answer on May 13, 2026 at 11:24 am

    I’ve added a few lines to your code. That’s sufficient to make it clear why this is disallowed:

    void f(vector<const T*>& p)
     {
        static const T ct;
        p.push_back(&ct); // adds a const T* to nonConstVec !
     }
     int main()
     { 
      vector<T*> nonConstVec;
      f(nonConstVec);
      nonConstVec.back()->nonConstFunction();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this situation: void doSmth1(std::map<int,int> const& m); void doSmth2(std::map<int,int> const& m) { std::map<int,int> m2
Consider this program: #include <map> #include <vector> typedef std::vector<int> IntVector; typedef std::map<IntVector,double> Map; void
Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
Consider this code: int main() { int e; prn(e); return 0; } void prn(double
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
I have a trouble with references. Consider this code: void pseudo_increase(int a){a++;} int main(){
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
I have the following problem. Consider the classes class face { virtual std::vector<ptr>& get_vertices(void)
Consider this: void l(Event const& e) { KeyEvent& k = (KeyEvent&)e; std::cout<<k.action<< <<k.keyCode; }
consider following: 1st APPROACH: public void f3() { f2(); f1(); } and this ...

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.