Jump to content
  • Advertisement
Sign in to follow this  
u235

Compiler error C2061

This topic is 3881 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class whose contructor takes as an argument an object of a type that I made. When I compile this, the compiler gives me a C2061 syntax error: indentifer "className". Here is a short example of what is going on:
class A
{
    A();
    ~A();

    //Other stuff
};

class B
{
    B(A a);  //<--C2061 syntax error 'A'
    ~B();

    //Other stuff
};

I looked up this error on MSDN and it didn't give much useful information. From MSDN:
Quote:
The compiler found an identifier where it wasn't expected. Make sure that identifier is declared before you use it. An initializer may be enclosed by parentheses. To avoid this problem, enclose the declarator in parentheses or make it a typedef. This error could also be caused when the compiler detects an expression as a class template argument; use typename to tell the compiler it is a type.
As far as I can tell, what I am doing doesn't fit any of these problems, so I am at a loss. If anyone can shed some light on this I would appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
That looks fine. I assume that the actual code has the classes in separate files, this may mean that B.h doesn't have A.h file included.

Share this post


Link to post
Share on other sites
Odd...

I tested it with my copy of MSVC++ 2005 and it worked fine...

I am thinking something else may be causing the error.

Share this post


Link to post
Share on other sites
Quote:
Original post by yaustar
this may mean that B.h doesn't have A.h file included.

I concur. Make sure you've included the correct files.

Share this post


Link to post
Share on other sites
Well, as of time of OP, I was including a header that in turn included all the other headers of the project. After reading your replies, I explicity included A.h in B.h and got the same results. Thanks.

Share this post


Link to post
Share on other sites
Quote:

I think I figured it out. Is it bad if A.h includes itself?

Yes. However, as long as your header files contain inclusion guards, you should not get any errors.

Share this post


Link to post
Share on other sites
Quote:
Original post by Crypter
Quote:

I think I figured it out. Is it bad if A.h includes itself?

Yes. However, as long as your header files contain inclusion guards, you should not get any errors.


Which I didn't bother to do the first time around and didn't originally think of as a possible cause of the error. So they're there now and it's fine. Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!