编译错误:类名称未命名类型。 [英] Compilation Error:Class name does not name a type.

查看:101
本文介绍了编译错误:类名称未命名类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi groups,


i创建了2.cpp和.h(标题)文件和一个main.cpp文件,例如

as file1.cpp和.h类似的file2.cpp& .h。

i也包含了适当的头文件。现在我正在创建类A的

对象(在file1.h中声明和定义)到类

B(在file2.h中声明并定义)。我收到一个错误

class a没有命名一个类型,我已经创建的对象是

未声明。我无法理解为什么会出现这个错误,因为我还有b $ b包括相关的头文件。


可以帮助解决这个问题。


提前付款...

解决方案

sharat写道:


hi groups,


i创建了2 .cpp和.h(标题)文件和一个main.cpp文件,例如

作为file1.cpp和.h类似file2.cpp& .h。

i也包含了适当的头文件。现在我正在创建类A的

对象(在file1.h中声明和定义)到类

B(在file2.h中声明并定义)。我收到一个错误

class a没有命名一个类型,我已经创建的对象是

未声明。我无法理解为什么会出现这个错误,因为我还有b $ b包括相关的头文件。


可以帮助解决这个问题。



请发布一个给出问题的最小例子。否则所有

你都可以猜到。


-

Ian Collins。


4月19日凌晨2:28,sharat< aaliya.zar ... @ gmail.comwrote:


hi groups,


i创建了2 .cpp和.h(标题)文件和一个main.cpp文件,例如/ b $ b作为file1.cpp和.h类似文件2。 cpp& .h。

i也包含了适当的头文件。现在我正在创建类A的

对象(在file1.h中声明和定义)到类

B(在file2.h中声明并定义)。我收到一个错误

class a没有命名一个类型,我已经创建的对象是

未声明。我无法理解为什么会出现这个错误,因为我还有b $ b包括相关的头文件。


可以帮助解决这个问题。


提前付款...



除非您显示代码否则。

请注意< A级和< a类不对应。

所以错误可能是一个基本错误。


这是我的代码..


//file1.cpp

使用命名空间std;

#include" file1.h"

void plot_class :: fun1()

{

cout<<" \ n PLOT CLASS \ n" ;;

}


//file1.h

#ifndef FILE1_H

#define FILE_H


#include" file2.h"

class plot_class

{

public:

int p;

zone_class zone_obj;

void fun1();


};

#endif


同样,

//file2.cpp

#include" file2.h"

void zone_class :: fun_zone()

{

cout<<" \ n zone class \\\
" ;;

}


//file2.h

#ifndef FILE2_H

#define FILE2_H

#include" fil e1.cpp


class zone_class

{

public:

int z;

plot_class plot_obj;

void fun_zone();

};

#endif


和main.cpp如下。


#include< iostream>

#include" file1.cpp"

#include" file2.cpp"

using namespace std;

int main()

{

cout<<" \ n Hello World \ n";

zone_class zone_obj1;


zone_obj1.fun_zone();
< br $>
}


i我正在使用gcc编译器..编译后我得到以下

错误


hi groups,

i have created 2 .cpp and .h(header) file and one main.cpp file, such
as file1.cpp and .h similarly file2.cpp & .h .
i have include the apropriate header files also .now i am creating the
object of class A (which is declare and define in file1.h) into class
B(which is declare and define in file2.h). i am getting an error that
"class a " doesnot name a type and the object i have creted is
undeclared . i am unable to get why this error is coming ,as i have
includede the related header files also.

can any body help to solve this problem.

Thanx in advance...

解决方案

sharat wrote:

hi groups,

i have created 2 .cpp and .h(header) file and one main.cpp file, such
as file1.cpp and .h similarly file2.cpp & .h .
i have include the apropriate header files also .now i am creating the
object of class A (which is declare and define in file1.h) into class
B(which is declare and define in file2.h). i am getting an error that
"class a " doesnot name a type and the object i have creted is
undeclared . i am unable to get why this error is coming ,as i have
includede the related header files also.

can any body help to solve this problem.

Please post a minimal example that gives your problem. Otherwise all
you can hope for is a guess.

--
Ian Collins.


On Apr 19, 2:28 am, sharat <aaliya.zar...@gmail.comwrote:

hi groups,

i have created 2 .cpp and .h(header) file and one main.cpp file, such
as file1.cpp and .h similarly file2.cpp & .h .
i have include the apropriate header files also .now i am creating the
object of class A (which is declare and define in file1.h) into class
B(which is declare and define in file2.h). i am getting an error that
"class a " doesnot name a type and the object i have creted is
undeclared . i am unable to get why this error is coming ,as i have
includede the related header files also.

can any body help to solve this problem.

Thanx in advance...


Not unless you show code.
Note that < class A and < class a do not correspond.
So the error is probably a fundamental one.


here is my code ..

//file1.cpp
using namespace std;
#include "file1.h"
void plot_class::fun1()
{
cout<<"\n PLOT CLASS \n";
}

//file1.h
#ifndef FILE1_H
#define FILE_H

#include"file2.h"
class plot_class
{
public:
int p;
zone_class zone_obj;
void fun1();

};
#endif

similarly ,
//file2.cpp
#include"file2.h"
void zone_class ::fun_zone()
{
cout<<"\n zone class \n";
}

//file2.h
#ifndef FILE2_H
#define FILE2_H
#include"file1.cpp"

class zone_class
{
public:
int z;
plot_class plot_obj;
void fun_zone();
};
#endif

and main.cpp is as follows.

#include<iostream>
#include"file1.cpp"
#include"file2.cpp"
using namespace std;
int main()
{
cout<<"\n Hello World\n";
zone_class zone_obj1;

zone_obj1.fun_zone();

}

i am using gcc compiler ..after compiling i am getting the following
errors


这篇关于编译错误:类名称未命名类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆