51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> C >> 文章正文

Apple was not declared in this scope

更新时间:2012-3-28:  来源:51代码网

first.h
#ifndef FIRST_H
#define FIRST_H
#include <iostream>
using namespace std;

class Apple
{
  public:
  Apple(int a,int b);
  double cnr() const;
  int fn(int x)const;
  private:
  int n;
  int r;
};
#endif
*****************************************************************************************
function.cpp
#include <iostream>
#include "first.h"
using namespace std;
Apple::Apple(int a,int b)
{
  n = a, r = b;
}
double Apple::cnr() const
{
  double sum;
  sum = fn(n) / (fn(r) * fn(n-r));

  return sum;

}

int Apple::fn(int x) const
{
  if(n <= 1)
  {
  return 1;
  }
  else
  {
  return n * f(n - 1);
  }
}
*******************************************************************
main.cpp
#ifndef FIRST_H
#define FIRST_H
#include <iostream>
#include "first.h"

using namespace std;

int main()
{
  Apple a(4,3);
  cout << a.cnr() <<endl;
  return 0;
}
#endif
************************************
程序写完之后,编译器提示Apple was not declared in this scope.
这似乎是说Apple类并没有被定义。可是我已经在first.h中定义了啊,而且也将first.h包含进main.cpp中了。
怎么还会出现这种状况?我用的是codeblocks10.05

main.cpp不要这个
#ifndef FIRST_H
#define FIRST_H

#endif

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |