关于包含问题的问题 [英] Question about include problems

查看:125
本文介绍了关于包含问题的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我包含头文件,它说无法找到函数定义,

但是当我包含cpp文件时,它有效,

为什么...



in Ah

I include the header file, it says cannot find the function definition,
but when I include the cpp file, it works,
why...

in A.h

#ifndef A_H
#define A_H

#include <stdlib.h>

class A{
  int member1;
 public:
  void Assign(int v);
  void Print();
};

#endif





in A. cpp



in A.cpp

#include "A.h"
#include <iostream>

using namespace std;

void A::Assign(int v){
  member1 = v;
}
void A::Print(){
  cout<<member1<<endl;
}




main.cpp中的




in main.cpp

#include <stdlib.h>
#include "A.h";

int main(){
  A a1;
  a1.Assign(1);
  a1.Print();
  return 0;







错误:
main.cpp中的
:未定义参考A ::分配......



谢谢




error:
in main.cpp: undefined ref to A::Assign...

Thanks

推荐答案

一切正确。好吧,包括< stdlib.h> 它完全是多余的。你不应该有这个错误。也许文件实际上是不同的,或者某些文件实际上没有包含在项目中,或者其他什么。文件本身是正确的。好吧,尝试从头开始重新创建项目(使用这些文件,不要使用预编译的头文件),具有相同的内容;它会工作。



-SA
All correct. Well, included <stdlib.h> it totally redundant. You should not have this error. Maybe the files are actually different, or some files are not actually included in project, or something. The files themselves are correct. Well, try to recreate the project from scratch (with such files, don''t use precompiled headers) accurately, with the same exact content; it will work.

—SA


在Main.cpp中,尝试使用 #include ,而不是 #include < 啊< u>>

干杯

Andi
In Main.cpp, try using #include "A.h", not #include <A.h>.
Cheers
Andi


你有没有A. cpp在你的项目中。看起来链接器抱怨它没有找到A :: Assign的定义。



你应该给我们你收到的确切错误信息。这可以表明我的假设是否正确。
Have you included A.cpp in you project. Looks like the linker is complaining that it doesn''t find the definition of A::Assign.

You should give us the exact error message that you are receiving. That could show if my assumption is true.


这篇关于关于包含问题的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆