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

  • Home
  • SEARCH
  • 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 54671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:15:24+00:00 2026-05-10T17:15:24+00:00

I’m trying to get my head around why the following doesn’t work. I have

  • 0

I’m trying to get my head around why the following doesn’t work. I have a std::vector and I want to call a static member function of it’s contained value_type like so:

std::vector<Vector> v; unsigned u = v.value_type::Dim(); 

where Vector is in fact a typedef for a templated type:

template <typename T, unsigned U> class SVector;  typedef SVector<double, 2> Vector; //two-dimensional SVector containing doubles 

and the static member function Dim() actually inlines the dimensionality U of the Vector.

Now the compiler returns an error message saying:

 error: ‘SVector<double, 2u>’ is not a base of   ‘std::vector<SVector<double, 2u>, std::allocator<SVector<double, 2u> > > 

which puzzles me. I can replace the apparently offending line by

unsigned u = Vector::Dim(); 

and that works, but is obviously ugly as it hardcodes assumptions about the value_type of v… Thanks!

  • 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. 2026-05-10T17:15:24+00:00Added an answer on May 10, 2026 at 5:15 pm

    You are accessing the value_type trough the variable instance and not the variable type.

    Method 1 – this works:

    typedef std::vector<Vector> MyVector; MyVector v; unsigned u = MyVector::value_type::Dim(); 

    Method 2 – or this:

    std::vector<Vector> v; unsigned u = std::vector<Vector>::value_type::Dim(); 

    If you typedef like on method 1 you do not hardcode assumptions on vector template parameter and you write clean code.


    Edit: Expanded to explain the behavior for this issue as requested by question owner:

    The scope resolution operator :: has higher precedence than any other C++ operator. This includes the Member access from an object . operator. Thus when you write something like:

    unsigned u= v.value_type::Dim(); 

    this resolves to the following C++ code:

    unsigned u = v.SVector<double, 2>::Dim(); 

    and ultimately what is resolved first is the SVector<double, 2>::Dim() part. This would force the vector instance declared trough variable v to have a templatized inner class named SVector. And because this does not happen this results in error:

    error C2039: 'SVector<double,2>' : is not a member of 'std::vector<_Ty>' 

    STL vector would have to be ‘expanded’ for each usage of this pattern (accessing value_type trough variable instance and not variable type). This is not a good solution as it leads to lots of boilerplate and unnecessary and unmaintainable code. By following the above mentioned solutions you avoid all this and can easily do what you wanted.

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

Sidebar

Ask A Question

Stats

  • Questions 51k
  • Answers 51k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer True Persistence Ignorance. Complete POCO Support. No Magic String. May 11, 2026 at 6:33 am
  • added an answer SELECT TOP 500 CONVERT(INT, CONVERT(VARBINARY(16), NEWID())) FROM dbo.MyTable May 11, 2026 at 6:33 am
  • added an answer You need to add and use a Private Accessor. Right… May 11, 2026 at 6:33 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.