关于VC++.NET2005 的win32控制台一个编程

来源:百度知道 编辑:UC知道 时间:2024/05/23 12:47:38
#include<iostream>
#include<math.h>
using namespace std;
int GetRoot(float a, float b, float c, double *root); //声明一个全局函数

void main()
{
float a = 2.0, b = 6.0, c = 3.0;
double root[2];
int n = GetRoot(a, b, c, root);
if(n<1)
cout<<"方程无根!"<<endl;
else{
cout<<"方程有"<<n<<"根"<<endl;
for(int i=0;i<n;i++)
cout<<"根"<<i+1<<";"<<root[i]<<"\t";
}
cout<<endl;
}

编译提示有错误
各位大侠看看

1.没有编译的错误。但是连接时会出错——如果你没有在项目的其他地方定义GetRoot函数的话。
2.root数组是否初始化都没关系。因为调用GetRoot()函数时,传递的是一个指向root[0]的指针。而double root[2]; 之后就已经为root数组分配空间了。
3.建议楼主复习一下多文件源代码编译、函数调用的知识。

int GetRoot(float a, float b, float c, double *root); //声明一个全局函数

你应该把这函数写完
别只写一个函数原形

还有啊,你的root数组没有初始化,这样也会报错的。