" 'yc' can not be used as a function"错误C++
" 'yc' can not be used as a function" error in C++
我正在使用C 计算NACA 4数字翼型坐标。在此代码中,我使用Armadillo库的Linspace功能将X分为线性间隔点。当我使用for循环来计算每个 x
的值的 yc
的值时,我得到错误" yc"无法用作函数。感谢您的帮助。
#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;
}
yc
是单个浮点。
编译器将symbol( )
视为函数调用。这就是错误的含义。
也许创建YC
的数组float yc[gp];
并使用
yc[i] = ....
突出显示-yc[gp]
可能不起作用,所以
float * yc = new float[gp];
,在main()
delete []yc;
这是一个示例,如何将std::vector
用于此类任务。
vector<float> v(size);
的声明用float
的size
值填充向量,这些值均设置为0.0
,这是float
的标准值:
#include <iostream>
#include <vector>
using namespace std;
// demonstrates how a vector is used as a better variadic array:
void vector_usage(int size){
// initializing a vector with size 0 values
std::vector<float> v(size);
// fill in some (not very meaningful) values
for(int i=0; i<size; ++i) {
if ((4 <= i) && (i < 8))
v[i] = 15.0/i;
}
// inspect the result on console:
for (auto e: v) {
cout << e << " ";
}
cout << endl;
// hopefully having learned something ;)
}
int main() {
vector_usage(12);
return 0;
}
请参阅IDEONE.com上的实时演示...
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- Confusion: decltype vs std::function
- 为什么 std::function 可以作为 std::not2 的参数?
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- 传递给std::function template的template参数究竟代表什么
- 将带有unique_ptr的可变 lambda 传递给 const&std::function
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- "no matching function for call to 'Vector::Vector'"错误
- 如何在向量中删除 std::function<void()>?
- 不断"Attempting to reference a deleted function"
- 将函数包装器转换为 std::function
- 类型擦除的std::function与虚拟函数调用的开销
- C++ std::function 对于类 exept 的所有实例都是空的(只有 Visual2019 编译器问题)
- 如果模板没有可变参数,则 Lambda 被推导出为 std::function
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 模板规范获取'Ambiguous call to overloaded function'
- 将 lambda 表达式传递给 std::function in C++
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?