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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:19:44+00:00 2026-06-13T02:19:44+00:00

I came up with my own little class called TinyVector. And now I’m trying

  • 0

I came up with my own little class called TinyVector. And now I’m trying to use std::inner_product on it. But I can’t get it to work and I don’t understand why this does not work.
I’m using Visual Studio 2012.

#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

template<class T, int N>
class TinyVector {
public:
    TinyVector() { data = vector<T>(N, 0); }
    explicit TinyVector(const T initVal) { data = vector<T>(N, initVal); }
    ~TinyVector() { data.clear(); }
    inline T& operator[](int i) { return data[i]; }
    inline T operator[](int i) const { return data[i]; }
    inline vector<T>::const_iterator begin() const { return data.begin(); } //Line 15
    inline vector<T>::const_iterator end() const { return data.end(); } //Line 16
private:
    vector<T> data;
};

template<class T, int N>
inline double dot(const TinyVector<T,N>& A, const TinyVector<T,N>&  B)
{
    return inner_product(A.begin(), A.end(), B.begin(), 0.0);
}

int main()
{
    TinyVector<double, 10> Ty;
    for (int i = 0; i < 10; ++i)
        Ty[i] = i;

    cout << dot(Ty,Ty) << endl;
}

The compiler tells me:
syntax error : missing ‘;’ before identifier ‘begin’ on line 15.
missing type specifier – int assumed. Note: C++ does not support default-int on line 15.
syntax error : missing ‘;’ before identifier ‘end’ on line 16.
missing type specifier – int assumed. Note: C++ does not support default-int on line 16.

But changing vector<T>::const_iterator into vector::const_iterator doesn’t seem like the way to go.
Also changing it to ‘auto’ does not work. This gives me “expected a trailing return type”.
If I delete line 15,16 and 17 and replace A.begin() with A.data.begin() and the next two arguments accoringly, everything is fine.
But why doesn’t my original code work, and how can I get it to work?

  • 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-13T02:19:45+00:00Added an answer on June 13, 2026 at 2:19 am

    You need to write

    inline typename vector<T>::const_iterator begin() const { return data.begin(); } //Line 15
           ^^^^^^^^
    

    This is because vector<T>::const_iterator is a dependent name (it is dependent on the type parameter T) and so the compiler needs to be told that vector<T>::const_iterator is a type (and not, say, an enum value or static data member).

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

Sidebar

Related Questions

I am trying to learn some python coding on my own and I came
We came across a bunch of pre-defined Build Macros for instance $(SolutionDir), but can
Reading the design guidelines. I came across a little issue while trying to practice
I can extend the ToolTip and create my own RichToolTip but I don't understand
I've came across this use case: Multiple template files have their own JavaScript code
I came across a problem I cannot solve on my own concerning the downloadable
(Came up with this question in the course of trying to answer this other
I came accross this: t = Clamp(t/d, 0, 1) but I'm not sure how
I came up with my own way to protect the moderators on my site.
I came across God which seems good but I am wondering if anyone knows

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.