C++ C++;Visual studio错误C2995无法解决此问题
我有一个名为ArrayBag.h的头文件C++ C++;Visual studio错误C2995无法解决此问题,c++,visual-studio,visual-c++,C++,Visual Studio,Visual C++,我有一个名为ArrayBag.h的头文件 /** Header file for an array-based implementation of the ADT bag. @file ArrayBag.h */ #ifndef _ARRAY_BAG #define _ARRAY_BAG #include "BagInterface.h" template<class ItemType> class ArrayBag : public BagInterfac
/** Header file for an array-based implementation of the ADT bag.
@file ArrayBag.h */
#ifndef _ARRAY_BAG
#define _ARRAY_BAG
#include "BagInterface.h"
template<class ItemType>
class ArrayBag : public BagInterface<ItemType>
{
.
.
.
.
.
}; // end ArrayBag
#include "ArrayBag.cpp"
#endif
但是它不会建造,所以我不知道
看在上帝的份上,我搞不懂。请帮帮我,我快疯了。不要在头文件中包含.cpp文件。相反,将它们作为单独的编译单元进行编译。此外,请至少参阅,显示准确完整的错误消息。方法名是什么?在哪里申报?它的定义是什么?在何处以及如何使用?@igortandtnik错误消息是just function:“函数模板已经定义,方法名称只是在ArrayBag.cpp中实现的方法。所有这些方法您是否也向项目中添加了
ArrayBag.cpp
?它不会编译,因为本质上它包含自己<代码>main.cpp应该编译。最好将ArrayBag.cpp
重命名为类似于ArrayBagImpl.h
,这样就不会对独立编译的源文件产生混淆。不要在头文件中包含.cpp文件。相反,将它们作为单独的编译单元进行编译。此外,请至少参阅,显示准确完整的错误消息。方法名是什么?在哪里申报?它的定义是什么?在何处以及如何使用?@igortandtnik错误消息是just function:“函数模板已经定义,方法名称只是在ArrayBag.cpp中实现的方法。所有这些方法您是否也向项目中添加了ArrayBag.cpp
?它不会编译,因为本质上它包含自己<代码>main.cpp应该编译。最好将ArrayBag.cpp
重命名为类似于ArrayBagImpl.h
,这样就不会对独立编译的源文件产生混淆。
/* Implementation file for the class ArrayBag.
@file ArrayBag.cpp */
#include "ArrayBag.h"
template<class ItemType>
ArrayBag<ItemType>::ArrayBag(): itemCount(0), maxItems(DEFAULT_CAPACITY) {
}// end default constructor
.
.
.
.
.
.
basically implement more methods
#include <iostream>
#include <string>
#include "ArrayBag.h"
using namespace std;
int main(){
/// some code to test it
}
#include "ArrayBag.h"