Class name does not name a type in C++

前端 未结 10 1976
情深已故
情深已故 2020-12-08 09:37

I just started programming in C++, and I\'ve tried to create 2 classes where one will contain the other.

File A.h:

#ifndef _A_h
#define          


        
10条回答
  •  青春惊慌失措
    2020-12-08 10:09

    NOTE: Because people searching with the same keyword will land on this page, I am adding this answer which is not the cause for this compiler error in the above mentioned case.

    I was facing this error when I had an enum declared in some file which had one of the elements having the same symbol as my class name.

    e.g. if I declare an enum = {A, B, C} in some file which is included in another file where I declare an object of class A.

    This was throwing the same compiler error message mentioning that Class A does not name a type. There was no circular dependency in my case.

    So, be careful while naming classes and declaring enums (which might be visible, imported and used externally in other files) in C++.

提交回复
热议问题