关于linker一个奇怪的问题,请高手指点
-------------------test.h-------------------------
#ifndef _TEST_
#define _TEST_
#include <stdio.h>
class test
{
public:
void sayhello();
};
void test::sayhello()
{
printf("hello\n");
}
#endif
----------------------ta.h----------------------
#ifndef _TA_H_
#define _TA_H_
class ta
{
public:
void say();
};
#endif
---------------------ta.cpp----------------------
#include "StdAfx.h"
#include "ta.h"
#include "test.h"
void ta::say()
{
test obj;
obj.sayhello();
}
---------------------test_linker.cpp--------------------
#include "stdafx.h"
#include "test.h"
int _tmain(int argc, _TCHAR* argv[])
{
test obj;
obj.sayhello();
return 0;
}
编译时报告出错:sayhello重复定义。以上sayhello的函数定义是直接放在test.h中的。
如果加一个test.cpp,并将sayhello的函数定义放到test.cpp中,编译就没有问题。
这是为什么?请高手指点,多谢了