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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:02:52+00:00 2026-05-22T17:02:52+00:00

The following code is part of an interpolation function I wrote as part of

  • 0

The following code is part of an interpolation function I wrote as part of a larger project. The first version of this function returned the myScalar yval, but I modified it to return a flag on whether or not the function worked.

My question is this. The following code compiles when run by itself both on codepad.org and in a smaller Visual Studio project. In my larger project, though, I am getting error C2109 “subscript requires array or pointer type.” What could be going wrong?

Thanks in advance! — Joe

using namespace std;

template <class myScalar, class myXVec, class myYVec>
int finterp(int mode, myXVec xarray, myYVec yarray, int num_pts, myScalar xval, myScalar &yval)
{
   myScalar dx, dydx, xmin, xmax;
   int success_flag = 0;

   if (num_pts < 1) return success_flag;
   yval = yarray[0]; //Visual Studio error C2109

   //some more calculations are here

   success_flag = 1;
   return success_flag;
}

int main()
{
   double *xvec, *yvec;
   xvec = new double [5]; yvec = new double [5];
   for (int i = 0; i < 5; i++)
   {
      xvec[i] = (double)i;
      yvec[i] = (double)i+1;
   }
   double x, y;
   x = 3.0;
   int success = finterp(1, xvec, yvec, 5, x, y);
   cout << y << "  " << success << endl;
   return 0;
}

Output:

1> j:\london_study\irasshell_2011-05-13\iras_src\templateutilityfunctions.h(74): 
   error C2109: subscript requires array or pointer type 
1> j:\london_study\irasshell_2011-05-13\iras_src\hydpowclass.cpp(41) : 
   see reference to function template instantiation 'int finterp<double,std::vector<_Ty>,double>(int,myXVec,myYVec,int,myScalar,myScalar &)' being compiled 
1> with 
1> [ 
1> _Ty=double, 
1> myXVec=std::vector<double>,
1> myYVec=double, 
1> myScalar=double 
1> ] 
  • 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-22T17:02:53+00:00Added an answer on May 22, 2026 at 5:02 pm

    As per your comment, in your real code a mere double is being passed in for yarray rather than a double* or std::vector<double>. This is a simple case of having a sufficiently small, but incorrect, repro — the real error lies in your real code.

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

Sidebar

Related Questions

I often see the following code: (function () { // init part })(); but
This following code snippet works fine using jQuery1.2.3, but it doesn’t work with latest
I've been trying to find what the problem is to this following code part.
I have the following vba code is part of a larger script. The issue
As part of answering another question, I wrote the following code whose behaviour seems
I use EFCodefirst. Most of you know, but the following code is part of
I am using the following code as part of an autocomplete script to avoid
I have the following code, which is run every 10ms as part of a
Google optimizer includes the following snippet as part of their conversion code. Unfortunately, the
The following code works great in IE, but not in FF or Safari. I

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.