visual studio 2008 - c++中未声明的标识符(错误C2065)
visual studio 2008 - Undeclared identifier (error C2065) in c++
我正在实现一个头文件"IVideoPlayer.h",我已经创建了一个抽象类"IVideoPlayer"。
class IVideoPlayer
{
public:
// Initialization
virtual bool Load(const char* pFilePath, bool useSubtitles = false) = 0;
virtual bool Start() = 0;
virtual bool Stop() = 0;
//....
};
其中的函数定义在文件" videoplayer。cpp"
#include "stdafx.h"
#include "IVideoPlayer.h"
#include <dshow.h>
HRESULT hr = CoInitialize(NULL);
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
class VideoPlayer:public IVideoPlayer
{
public:
bool Load(const char* pFilePath, bool useSubtitles = false)
{
EPlaybackStatus var1 = PBS_ERROR;
// Initialize the COM library.
if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");
return 0;
}
// Create the filter graph manager and query for interfaces.
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr))
{
printf("ERROR - Could not create the Filter Graph Manager.");
return 0;
}
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
// Build the graph. IMPORTANT: Change this string to a file on your system.
hr = pGraph->RenderFile(L"G:edit.wmv", NULL);
return 0;
}
bool Start()
{
if (SUCCEEDED(hr))
{
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr))
{
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);
// Note: Do not use INFINITE in a real application, because it
// can block indefinitely.
}
}
return 0;
}
bool Stop()
{
pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();
return 0;
}
};
检查头文件,我创建了文件sample.cpp
#include "stdafx.h"
#include "IVideoPlayer.h"
#include <stdio.h>
#include <conio.h>
int main(void)
{
VideoPlayer h;
h.Load("G:hila.wmv");
getch();
return 0;
}
错误如下:
Error 1 error C2065: 'VideoPlayer' : undeclared identifier
Error 2 error C2146: syntax error : missing ';' before identifier 'h'
Error 3 error C2065: 'h' : undeclared identifier
Error 4 error C2065: 'h' : undeclared identifier
Error 5 error C2228: left of '.Load' must have class/struct/union
为什么编译器显示它为未声明的标识符?我们接受任何帮助。提前感谢您
您从未包含任何定义了std
命名空间的头文件,因此using
(未定义)命名空间导致错误。你也不包括任何头定义VideoPlayer
类,主要是因为你已经决定把类定义在源文件,而不是头文件。
上述解释了前两个错误。其余的错误是由于第二个错误(VideoPlayer
未定义)而导致的后续错误。
您需要在放置VideoPlayer
类定义的地方创建一个头文件,就像IVideoPlayer
类的头文件一样。将VideoPlayer
成员函数的实现放在源文件中。然后将头文件包含在需要VideoPlayer
类的源文件中。
程序中没有std名称的定义,因为您没有使用任何包含命名空间std定义的标准头文件。至少修改这个指令
#include <stdio.h>
#include <cstdio>
还必须将类'VideoPlayer '的定义放在一个头文件中,并将该头文件包含在模块sample.cpp
您需要在顶部添加#include。'std'命名空间在iostream库中定义。你还需要在你的主cpp文件中做一个"Video Player"类的前向声明。
相关文章:
- 设置 Visual Studio for MPI: 找不到标识符错误
- 从子类访问模板类成员时出现"找不到标识符"错误
- 未声明的标识符错误,但变量定义正确 (?)
- 尝试使用类时获取标识符错误
- 我收到未声明的标识符错误,但我已包含头文件?
- 常量自动/标识符错误
- 为什么我的类对象会导致未申报的标识符错误
- C 未申报的标识符错误
- 在Visual Studio中使用C 类 - 未申报的标识符错误
- 编译器不喜欢我的类C++。获取未声明的标识符错误等
- 奇怪的未知标识符错误
- C 数组未申报的标识符错误
- 定义中未声明的标识符错误 C2065,显然存在
- 找不到标识符错误
- 稍后在程序中使用if-else构造内部声明的变量会导致未声明的标识符错误
- Xcode C++未声明的标识符错误
- 编译时未找到"log10"标识符错误
- 标识符错误之前缺少';' - 无法运行 MPI 示例
- 时间开始未找到标识符错误
- 声明项时出现未声明的标识符错误