Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

" 'yc' can not be used as a function" error in C++

I am calculating NACA 4 digit airfoil coordinates using C++. In this code I used armadillo library's linspace function to divide x into linearly spaced points. When I use a for loop to calculate yc's value for each x's value I get error "yc" can not be used as function. Thanks for helping.

#include<iostream>
#include<armadillo>
#include<vector>

using namespace std;
using namespace arma;
int main()
{

    float a[3];
    float c;
    int gp = 100;

    cout << "Please Enter NACA 4 digits" << endl;
    cout << "Please Enter 1st digit" << endl;
    cin >> a[0] ;
    cout << "Please Enter 2nd digit" << endl;
    cin >> a[1] ;
    cout << "Please Enter last 2 digits" << endl;
    cin >> a[2] ;
    cout << "Please Enter Chord Length" << endl;
    cin >> c;

    float m=(a[0]*c)/100;
    float p=(a[1]*c)/10;
    float t=(a[2]*c)/100;

    cout << m << endl;
    cout << p << endl;
    cout << t << endl;
    vec x = linspace<vec>(0, c, gp);
    float yc;
    for(int i=0;i<gp;++i)

        {
            if (x(i) = 0 && x(i) <= p){
            yc(i) = (m/(p*p))*((2*p*(x(i)))-(x(i)*x(i)));
        }
            if (x(i) > p && x(i) <= c) {
            yc(i) =(m/((1-p)*(1-p)))*((1-(2*p))+(2*p*x(i))-(x(i)*x(i)));
        }
        }
    cout<< yc <<endl;
return 0;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

yc is a single float.

The compiler treats symbol( ) as a function call. That is what the error means.

Perhaps create an array of yc

float yc[gp];

and use

yc[i] = ....

As highlighted - yc[gp] may not work, so

float * yc = new float[gp];

And at the end of main()

delete []yc;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...