1

I am implementing a header file "IVideoPlayer.h" and I have created an abstract class "IVideoPlayer".

class IVideoPlayer
{

public:
// Initialization
virtual bool Load(const char* pFilePath, bool useSubtitles = false) = 0;
    virtual bool Start() = 0;
    virtual bool Stop() = 0;
    //....
};

And the functions of that are defined in file "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;

    }
};

And to check the header file I have created file 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;
}

The errors are:

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 

Why compiler is showing it as undeclared identifer? Any help is accepted. Thanking you in advance

user3615925
  • 41
  • 1
  • 2
  • 4

3 Answers3

4

You never include any header files which defined the std namespace, so using that (undefined) namespace results in an error. You also don't include any header which defines the VideoPlayer class, mostly because you have decided to put the class definition in a source file instead of a header file.

The above accounts for the two first errors. The remaining errors are follow up errors because of the second error (VideoPlayer not defined).


You need to make a header file where you put the VideoPlayer class definition, much like the header file for the IVideoPlayer class. You put the implementation of the VideoPlayer member functions in the source file. Then include the header file in the source file where you need the VideoPlayer class.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thank you for suggestion. I removed namespace and first error is gone. But compiler is still showing the reaming errors. Is it because that a header file name and related source file name is different? – user3615925 May 08 '14 at 10:51
  • 2
    @user3615925: No, it's because you define `VideoPlayer` in a source file, rather than a header, so it's not available in other source files. You'll need to move the class definition into a header, and include that from `main.cpp`. – Mike Seymour May 08 '14 at 10:59
1

There is no definition of name std in your program because you do not use any standard header that contains the definition of namepsace std. At least change this directive

#include <stdio.h>

to

#include <cstdio>

Also you have to place the definition of class 'VideoPlayer in a header and include this header in module sample.cpp

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

You need to add #include at the top. 'std' namespace is defined in iostream library. Also you need to do a forward declaration of the "Video Player" class in your main cpp file .

dennis
  • 680
  • 1
  • 5
  • 11
  • In which way does this answer the OP's question? – πάντα ῥεῖ May 08 '14 at 10:46
  • Why would you include a header you don't need just to allow a using directive you don't need, which shouldn't be there in the first place? – Mike Seymour May 08 '14 at 10:47
  • @MikeSeymour: Perhaps you are right. If we are not using any functionality provided by 'std' namespace, then its not reqd. But its always better to let the developer know what is the missing link thats causing the error. And in this case header file inclusion is the missing link, at least thats what I thought initially. :) – dennis May 08 '14 at 10:53
  • 1
    You'll need more than a forward declaration if you want to create an object. The definition of `VideoPlayer` needs to be moved to a header. – Mike Seymour May 08 '14 at 10:58