我有以下课程:
// 缓冲区.cpp
#include "MonoSample.h"
#include "Buffer.h"
#define INBUFFERSIZEBLOCK 1024 // input block size
#define MAXBUFFERSIZE 1000000 // max buffer size (1MB)
#pragma warning (disable : 4996)
using std::endl;
using std::fstream;
Buffer::Buffer()
{
}
(...)
// 缓冲区.h
#pragma once
#include <string>
using std::string;
typedef struct WAV_HEADER
{
uint8_t RIFF[4];
uint32_t ChunkSize;
uint8_t WAVE[4];
uint8_t fmt[4];
uint32_t Subchunk1Size;
uint16_t audioFormat;
uint16_t numOfChan;
uint32_t samplesPerSec;
uint32_t bytesPerSec;
uint16_t blockAlign;
uint16_t bitsPerSample;
uint8_t Subchunk2ID[4];
uint32_t sampledDataLen;
} wavHdr, *pwavHdr;
class Buffer
{
private:
string wFileNamePath;
int nChannel;
wavHdr head;
unsigned long samplesLen;
unsigned long samplesPte;
FILE* wavFile;
MonoSample* firstSample;
public:
Buffer();
Buffer(string filePath, int id);
~Buffer();
wavHdr getHeader(); // retorna el header del fitxer wav
string getWavFileName(); // retorna el nom del fitxer wav
int getNumChannel(); // retorna el id del fitxer wav
bool ResetBuffer(); // inicia el bufer
void closeBuffer(); // allibera la memoria del buffer
bool openFile(string p, int n); // obre fitxer
MonoSample* getFirstSample(); // punter a la primera mostra mono
MonoSample* getSample(int n); // pointer to 16 bits of the mono sample n
};
// main.cpp
#include "Buffer.cpp"
#include "MonoSample.h"
#include <iostream>
using namespace std;
#define NUMCANALS 16
int main()
{
(...)
}
当我运行我的程序时,我收到以下错误:
严重性代码 描述 项目文件行抑制状态错误 LNK2005 "public: class MonoSample * __cdecl Buffer::getSample(int)" (?getSample@Buffer@@QEAAPEAVMonoSample@@H@Z) 已在 Buffer.obj 中定义
严重性代码 描述 项目文件行抑制状态错误 LNK2005 "public: class MonoSample * __cdecl Buffer::getFirstSample(void)" (?getFirstSample@Buffer@@QEAAPEAVMonoSample@@XZ) 已在 Buffer.obj 中定义
(...)
我认为这是因为我在 main.cpp 中写了 #include "Buffer.cpp" 但如果没有 #include 我不知道该怎么做......如果我不这样做,我该如何使用 Buffer 对象有这个#include 吗?
谢谢!