| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 644 人关注过本帖
标题:看看这个程序怎么错了!
只看楼主 加入收藏
xiangz9025
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-10-30
结帖率:100%
收藏
 问题点数:0 回复次数:1 
看看这个程序怎么错了!
#include "iostream.h"
#include "stdlib.h"
#define N 12

void process(float *p,int n,float (*fun)());
/*float arr_sum(float arr[],int n)
{
    int i;
    float sum=0;
    for(i=0;i<n;i++)
        sum+=arr[i];
    cout<<"数组和为:";
    return(sum);
}*/
void process(float *p,int n,float  (*fun)(float *p,int n))   //调用功能函数
{
    float result;
    result = (*fun)(p,n);
    
    cout<<result<<endl;
    return ;
}
float arr_odd(float *p,int n)
{
    int i;
    float sum=0;
    for(i=0;i<n;i+=2,p+=2)                    //这个地方值得自己好好学习
        sum+=*p;
    cout<<"奇数和:";
    return(sum);
}

/*float arr_max(float *p,int n)
{
    int i;
    float m;
    m = *p;
    for(i=0;i<n;i++,p++)
        if(*p>m)  m = *p;
        cout<<"最大值为:";
        return(m);

}

float arr_ave(float *p,int n)
{
    int i;
    float a;
    for(i=0;i<n;i++,p++)
        a+=*p;
        a=a/n;
        cout<<"平均值为:";
        return(a);

}*/

void main()
{
  int i;
  float a[N];
  cout<<"输入要选课的系统:";
  for(i=0;i<N;i++)
      cin>>a[i];
  float arr_odd(),(*pt)(float *p,int n);
  int n = N;
  pt = arr_odd();
  process(a,n,pt);
  //process(a,N,arr_odd);
  //process(a,N,arr_max);
  //process(a,N,arr_ave);
    
}

Compiling...
21function.cpp
D:\c++\book\21function\21function.cpp(20) : error C2197: 'float (__cdecl *)(void)' : too many actual parameters
D:\c++\book\21function\21function.cpp(68) : error C2440: '=' : cannot convert from 'float' to 'float (__cdecl *)(void)'
        There is no context in which this conversion is possible
D:\c++\book\21function\21function.cpp(71) : error C2664: 'process' : cannot convert parameter 3 from 'float (float *,int)' to 'float (__cdecl *)(void)'
        None of the functions with this name in scope match the target type
D:\c++\book\21function\21function.cpp(72) : error C2664: 'process' : cannot convert parameter 3 from 'float (float *,int)' to 'float (__cdecl *)(void)'
        None of the functions with this name in scope match the target type
执行 cl.exe 时出错.
那位仁兄帮忙看一下,小弟真实感激不尽啊!
搜索更多相关主题的帖子: include process return result 
2007-12-01 12:35
first_love
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2006-11-11
收藏
得分:0 
真是乱七八糟呀!float arr_odd(),(*pt)(float *p,int n);这是什么意思呀?定义还是调用?不懂…………

2007-12-01 15:02
快速回复:看看这个程序怎么错了!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023125 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved