共三个文件
***************
head.h
#include <iostream>
using namespace std;
class A
{
public:
int val;
A(int a=0){val=a;}
A( const A&a){val=a.val;}
void show();
};
/*下面是类中的函数定义*/
#ifndef A_H
#define A_H
void A::show() //虽然做了保护,但编译器还是提示重定义,为什么??
{
cout<<val<<endl;
}
#endif;
*************
c++.cpp
#include "head.h"
#include <iostream>
#include <conio.h>
int main()
{
A a;
a.show();
getch();
return 0;
}
***********************
dingyi.cpp
#include "head.h" //去掉这个源文件的调用,可以正常运行
***************
head.h
#include <iostream>
using namespace std;
class A
{
public:
int val;
A(int a=0){val=a;}
A( const A&a){val=a.val;}
void show();
};
/*下面是类中的函数定义*/
#ifndef A_H
#define A_H
void A::show() //虽然做了保护,但编译器还是提示重定义,为什么??
{
cout<<val<<endl;
}
#endif;
*************
c++.cpp
#include "head.h"
#include <iostream>
#include <conio.h>
int main()
{
A a;
a.show();
getch();
return 0;
}
***********************
dingyi.cpp
#include "head.h" //去掉这个源文件的调用,可以正常运行



