473,378 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Compilation Error:Class name does not name a type.

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...

Apr 19 '07 #1
13 30278
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.
Apr 19 '07 #2
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.

Apr 19 '07 #3
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
$ g++ main.cpp
file2.h:9: error: 'plot_class' does not name a type


Apr 19 '07 #4
* sharat:
here is my code ..

//file1.cpp
using namespace std;
#include "file1.h"
Preferentially include the header file before /anything/ else, so that
you get a check (however fallible) that the header file is OK on its own.

void plot_class::fun1()
{
cout<<"\n PLOT CLASS \n";
}
You haven't included <iostreamand <ostream>. OK, you have, in the
main program, but that's a bug masking a bug.

//file1.h
#ifndef FILE1_H
#define FILE_H
Typo.

#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"
Typo or thinko.

Don't include implementation files, ever.

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"
Don't include implementation files, ever.

#include"file2.cpp"
Don't include implementation files, ever.

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
$ g++ main.cpp
file2.h:9: error: 'plot_class' does not name a type
In [main.cpp] you include first of all [file1.cpp], which includes
[file1.h], which includes [file2.h], which at line references
plot_class, which so far hasn't been declared or defined.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 19 '07 #5
Le 19.04.2007 11:02, sharat a ecrit:
here is my code ..

class plot_class
{
public:
int p;
zone_class zone_obj;
void fun1();

};
So, a plot_class contains an int and a zone_class...
class zone_class
{
public:
int z;
plot_class plot_obj;
void fun_zone();
};
So, a zone_class contains an int and a plot_class...

Question: assuming an int is 4 bytes and there is no extra byte wasted,
can you compute the size of a plot_class? the size of a zone_class?

Do you see your problem now?

--
___________
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Pour bien répondre avec Google, ne pas cliquer
-'(__) « Répondre », mais « Afficher les options »,
_/___(_) puis cliquer « Répondre » (parmi les options).
Apr 19 '07 #6
Serge Paccalin wrote:
Le 19.04.2007 11:02, sharat a ecrit:
>here is my code ..

class plot_class
{
public:
int p;
zone_class zone_obj;
void fun1();

};

So, a plot_class contains an int and a zone_class...
>class zone_class
{
public:
int z;
plot_class plot_obj;
void fun_zone();
};

So, a zone_class contains an int and a plot_class...

Question: assuming an int is 4 bytes and there is no extra byte wasted,
Extra byte wasted?
can you compute the size of a plot_class? the size of a zone_class?
How can it matter?
Do you see your problem now?
I don't
Apr 19 '07 #7
Le 19.04.2007 11:16, anon a ecrit:
Serge Paccalin wrote:
>Question: assuming an int is 4 bytes and there is no extra byte wasted,
Extra byte wasted?
For alignment purposes, for instance. "Wasted" is probably not the
correct word, but English is not my native language either.
>can you compute the size of a plot_class? the size of a zone_class?
How can it matter?
Just try it.
>Do you see your problem now?
I don't
Circularity.

--
___________
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Pour bien répondre avec Google, ne pas cliquer
-'(__) « Répondre », mais « Afficher les options »,
_/___(_) puis cliquer « Répondre » (parmi les options).
Apr 19 '07 #8
Serge Paccalin wrote:
Le 19.04.2007 11:16, anon a ecrit:
>Serge Paccalin wrote:
>>Question: assuming an int is 4 bytes and there is no extra byte wasted,
Extra byte wasted?

For alignment purposes, for instance. "Wasted" is probably not the
correct word, but English is not my native language either.
I do not see where a byte can be wasted there, and how can it influence
the error he is getting.

>>can you compute the size of a plot_class? the size of a zone_class?
How can it matter?

Just try it.
>>Do you see your problem now?
I don't

Circularity.
Do you mean circularity with includes or what?
He should have declared classes, instead of including header files
(including source files is out of question here)
Like this:

//file1.h
#ifndef FILE1_H
#define FILE1_H

class zone_class;

class plot_class
{
public:
int p;
zone_class zone_obj;
void fun1();

};
#endif

Similar for file2.h
Apr 19 '07 #9
anon wrote:
>
Do you mean circularity with includes or what?
class A has a member of type class B. Class B has a member of type
class A. How big is class A?

--
Ian Collins.
Apr 19 '07 #10
Ian Collins wrote:
anon wrote:
>Do you mean circularity with includes or what?

class A has a member of type class B. Class B has a member of type
class A. How big is class A?
Thanks for clarifications :)
I knew I have used something similar, but references instead of objects
Apr 19 '07 #11
still not clear

Apr 19 '07 #12
* sharat:
still not clear
In C++, if an object A contains another object B, it really directly
contains object B.

The size of object A is the size of its member object B plus the sizes
of whatever other members there are in object A, pluss the size of
compiler-inserted padding, if any.

Now, let type Y have some data member such that its size is at least 1.
If any object of type X contains an object of type Y, which in turn
contains an object of type X, which..., what's the size of an object of
type X? What's the size of an object of type Y?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 19 '07 #13
sharat wrote:
still not clear
You need to use pointers or references, instead of actual objects inside
your classes. Like in these headers:

//file1.h
#ifndef FILE1_H
#define FILE1_H

class zone_class;
class plot_class
{
public:
int p;
zone_class& zone_obj;
void fun1();

};
#endif

//file2.h
#ifndef FILE2_H
#define FILE2_H

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

Otherwise, object of class zone_class would contain an object of
plot_class class, which contains object of zone_class class, ... , to
infinity.

Apr 19 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Simon | last post by:
Hi, I create a new asp.net project and add one user control. When I would like to see the default page, I get the following error: Compilation Error Description: An error occurred during the...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
7
by: juli jul | last post by:
Hello, I am trying to compile a project and get the following error: A project with an Output Type of Class Library cannot be started directly Can somebody explain me why? Thank you very much!
1
by: dt | last post by:
Hi, I got compilation error: c:\gms\Services\DeviceManager\VCUE_Copy.h(134): warning C4346: 'MapType::value_type' : dependent name is not a type for the following codes: template <class...
4
by: john isaac | last post by:
this statement causes a compilation error: memberlist.name.push_back(newname); cannot convert std::string to char. memberlist is a vector...i is an integer that's interating in a...
6
by: Yan | last post by:
Here is the code: class A {}; void (A::*A) (); // Line 3 int main() { A a; // Line 6 return 0; }
9
by: subramanian | last post by:
Hello. Consider the following code fragment : enum TestEnum { val1 = 10, val2 = 100, val3 = 1000 }; class Test { public : enum TestEnum { val1 = 1, val2 val3 }; Test(int i = 0, int j = 0,...
2
by: subramanian | last post by:
Consider the following program: #include <iostream> #include <string> class Member { int x; int y; public: Member(int argx, int argy);
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.