C2061, and i don't know why

Hello guys,
I have a kind of annoying problem, seems basic in C++ but I can’t determine why, in TestParser.hh, I have a: error c2061: syntax error: identifier ‘TestFramer’, while I include properly (as long as I know) the library.
There is no two TestFramer.hh, so I am completely lost.

Help would be greatly appreciated !


Here is my code:

#ifndef TEST_FRAMER_HH
#define TEST_FRAMER_HH
#include "stdafx.h"

#include "FramedFilter.hh"
#include "TestParser.hh"




class TestFramer: public FramedFilter{

public:
TestFramer(UsageEnvironment& env, FramedSource* inputSource);
virtual ~TestFramer();


private:
	virtual void doGetNextFrame();

  static void continueReadProcessing(void* clientData,unsigned char* ptr, unsigned size,struct timeval presentationTime);

  void continueReadProcessing();

	TestParser fTestParser;

};


#endif














#include "stdafx.h"

#ifndef TEST_PARSER_HH
#define TEST_PARSER_HH



#include "SupportLog.h"

#include "StreamParser.hh"
#include "TestFramer.hh"

////////// TestParser definition //////////

class TestParser: public StreamParser {

public:
//error c2061: syntax error: identifier ‘TestFramer’
  TestParser( TestFramer* usingSource , FramedSource* inputSource);

  virtual ~TestParser();

public:
  void registerReadInterest(unsigned char* to, unsigned maxSize);

protected:
 // TestFramer* fUsingSource;


};

#endif

Open in new window

NoeroAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
You have a cyclic header dependency issue. TestRarser includes TestFramer and vice versa.

You need to forward declare rather than include headers cyclically.

http://www.eventhelix.com/realtimemantra/HeaderFileIncludePatterns.htm
divby0Commented:
the compiler falls in a definition error
since in both the files u define both the classes,
u shall remove one of the #include ".hh" files from one of the cpp


try this


#include "stdafx.h"

#ifndef TEST_PARSER_HH
#define TEST_PARSER_HH



#include "SupportLog.h"

#include "StreamParser.hh"
//remove this from here #include "TestFramer.hh"

////////// TestParser definition //////////
//and here add
class TestFramer;
class TestParser: public StreamParser {

public:
//error c2061: syntax error: identifier ‘TestFramer’
  TestParser( TestFramer* usingSource , FramedSource* inputSource);

  virtual ~TestParser();

public:
  void registerReadInterest(unsigned char* to, unsigned maxSize);

protected:
 // TestFramer* fUsingSource;


};

#endif

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itsmeandnobodyelseCommented:
You never may include stdafx.h in a header file. stdafx.h is a 'precompiled header' for cpp files only (where it must included as very first header). Throw it out of the .hh files.

>>>> You have a cyclic header dependency issue.

Exchange

#include "TestFramer.hh"

in TestParser.hh by

// forward declaration
class TestFramer;
itsmeandnobodyelseCommented:
FYI:

A #include statement actually *inserts* the header file line by line  into the current source file (and replaces the #include statement). Because of the definitions for header protection like #ifndef XXXX_HH  it would not read a header file twice but in case of a cyclic header dependency we have the case that while reading the second header which was included in the first header, the class of the first header wasn't parsed until yet, so that when compiling the second class it has error that the type of first class was unknown:

// class1.h
#ifndef CLASS1_H
#define CLASS1_H

#include "class2.h"

class Class1
{
      ...
      void any(Class2* c2);
};

#endif

// class2.h
#ifndef CLASS2_H
#define CLASS2_H

#include "class1.h"

class Class2
{
      ...
      void other(Class1* c1);
};

#endif

// main.cpp
#include "class1.h"
#include "class2.h"

int main()
{
     return 0;
}

with the above we get the following when compiling main.cpp

- #include "class1.h" in main.cpp reads class1.h
- CLASS1_H was not set
- sets CLASS1_H
- #include "class2.h" in class1.h reads class2.h
- CLASS2_H was not set
- sets CLASS2_H
- #include "class1.h" in class2.h reads class1.h
- CLASS1_H was already set, so class1.h was not parsed again
- statement "class Class2"  was parsed
- statement "{" was parsed"
- statement "void other(Class1* c1); was parsed
   ==> error 2061  Class1 unknown at this time
 

NoeroAuthor Commented:
Thank you all guys, it was difficult not to be unfair to give you points! All explanations were good and interesting.
Thank you again!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.