•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,605 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,492 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 681 | Replies: 5 | Solved
![]() |
hello,
i have a header file (intl.h)which contains the declaration of members of class intl
and the members functions are defined in 5 different headers
and i have one more header (floatl.h) which contains the total declaration of class floatl
and it's member functions
the over view is something like this
and methods of intl class are declared in separate headers
as i said and include no header files
now i write a header allheaders.h which include
all the header files i wrote
and in a program i included this allheaders.h file
and want to use the class floatl which inturn uses class intl
(floatl and intl have no relation at all in terms of oop concept)
when i compiled my final program compilation error was
intl doen not name a type
was there any mistake in including files?
thanks in advance
i have a header file (intl.h)which contains the declaration of members of class intl
and the members functions are defined in 5 different headers
and i have one more header (floatl.h) which contains the total declaration of class floatl
and it's member functions
the over view is something like this
cplusplus Syntax (Toggle Plain Text)
//this is intl.h # ifndef _header_i #define _header_i #include "floatl.h" #include <iostream> using namespace std; class intl { .. .. }; #endif
cplusplus Syntax (Toggle Plain Text)
//this is float_l.h #ifndef _header_f #define _header_f #include "intl.h" #include <cstring> using namespace std; class float { .. .. }; //all methods defined here
and methods of intl class are declared in separate headers
as i said and include no header files
now i write a header allheaders.h which include
all the header files i wrote
and in a program i included this allheaders.h file
and want to use the class floatl which inturn uses class intl
(floatl and intl have no relation at all in terms of oop concept)
when i compiled my final program compilation error was
intl doen not name a type
was there any mistake in including files?
thanks in advance
all the header files contain friend operators definitions
and order in allheaders.h was
intl.h
intl_mem-1
inrl-mem-2
...
..
floatl.h
i think i got what the logical error was as i am typing this !
intl were using floatl
floatl members were using intl
how to solve this !
because neither class definition was complete before calling other other class ,
but that class uses this class
and order in allheaders.h was
intl.h
intl_mem-1
inrl-mem-2
...
..
floatl.h
i think i got what the logical error was as i am typing this !
intl were using floatl
floatl members were using intl
how to solve this !
because neither class definition was complete before calling other other class ,
but that class uses this class
Last edited by tnvkrishna : Nov 9th, 2007 at 10:33 am.
•
•
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation:
Rep Power: 9
Solved Threads: 163
> intl were using floatl floatl members were using intl how to solve this !
to declare the floatl members using intl, a declaration of intl would suffice.
to define them, a definition of intl is required.
so do things in this order:
a. declare the classes first.
b. define the classes (which have declarations of their members)
c. define the members.
for example:
to declare the floatl members using intl, a declaration of intl would suffice.
to define them, a definition of intl is required.
so do things in this order:
a. declare the classes first.
b. define the classes (which have declarations of their members)
c. define the members.
for example:
//********* header b.h ***************
#ifndef _B_H_INCLUDED_
#define _B_H_INCLUDED_
struct A ;
// A has been declared; we can now declare (not yet define) functions using A
struct B
{
inline int b_fun( const A& a ) ;
int bm ;
A* a ;
friend inline int b_friend( B& b, const A& a ) ;
};
#endif // _B_H_INCLUDED_
//////////////////////////////////////////////////////////////////
//********* header a.h ***************
#ifndef _A_H_INCLUDED_
#define _A_H_INCLUDED_
struct B ;
struct A
{
inline int a_fun( const B& b ) ;
int am ;
friend inline int a_friend( A& a, const B& b ) ;
};
#endif // _A_H_INCLUDED_
/////////////////////////////////////////////////////////////////////
//********* header anything_else.h ***************
#ifndef _ANYTHING_ELSE_H_INCLUDED_
#define _ANYTHING_ELSE_H_INCLUDED_
#include "a.h"
#include "b.h"
// A and B have been defined; we can now define functions using A and B
int A::a_fun( const B& b ) { return am += b.bm ; }
int B::b_fun( const A& a ) { return bm += a.am ; }
int a_friend( A& a, const B& b ) { return a.am += b.bm ; }
int b_friend( B& b, const A& a ) { return b.bm += a.am ; }
#endif // _ANYTHING_ELSE_H_INCLUDED_ this is a strange problem!
i declared class floatl(not defined)int the header intl.h
and declared class intl(not defined)floatl in the header floatl.h
and the error was strange!
power_i.h: In function ‘intl power(intl, int)’:
power_i.h:21: error: invalid use of undefined type ‘struct floatl’
intl.h:4: error: forward declaration of ‘struct floatl’
power_i.h:21: error: invalid use of undefined type ‘struct floatl’
intl.h:4: error: forward declaration of ‘struct floatl’
why is th ecompiler reading class declaration as struct declaration?
i declared class floatl(not defined)int the header intl.h
and declared class intl(not defined)floatl in the header floatl.h
and the error was strange!
power_i.h: In function ‘intl power(intl, int)’:
power_i.h:21: error: invalid use of undefined type ‘struct floatl’
intl.h:4: error: forward declaration of ‘struct floatl’
power_i.h:21: error: invalid use of undefined type ‘struct floatl’
intl.h:4: error: forward declaration of ‘struct floatl’
why is th ecompiler reading class declaration as struct declaration?
Last edited by tnvkrishna : Nov 10th, 2007 at 4:19 am.
•
•
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation:
Rep Power: 9
Solved Threads: 163
> why is the compiler reading class declaration as struct declaration?
the compiler makes no distinction between a class or a struct in the declaration of the type. when the type is defined, the only difference between the two is the default access specifier.
so
also,
is identical to
for example, the following code will compile without errors:
> power_i.h:21: error: invalid use of undefined type ‘struct floatl
clearly means that
a. floatl has already been declared
b. floatl has not yet been defined
c. at line 21 in power_i.h, you are trying to use floati (not just in name, but in size)
> this is a strange problem!
no, it is not. it is a very commom problem that occurs when you try to use something
without having defined it.
the compiler makes no distinction between a class or a struct in the declaration of the type. when the type is defined, the only difference between the two is the default access specifier.
so
struct A { int i ; double d ; }; andclass A { public: int i ; double d ; }; are identical definitions.also,
class C {/*....*/}; class D : public C {/*...*/}; is identical to
struct C {private: /*...*/}; class D : C {/*...*/}; for example, the following code will compile without errors:
c++ Syntax (Toggle Plain Text)
struct A ; class A ; struct A ; int foobar( A arg1, A& arg2 ) ; // ok, use in name //int foobar( A arg1, A& arg2 ) { return arg2.a = arg1.a ; }; // uncomment the above and you get the error '.... undefined type ....' class A { public : int a ; }; struct A ; class A ; struct A ; int foobar( A arg1, A& arg2 ) { return arg2.a = arg1.a ; }; // ok class B ; struct B : public A { private : int b ; public : operator int() const { return a + b ; } }; int main() { struct A a1 ; class A a2 ; class B b1 ; struct B b2 ; return a1.a + a2.a + b1.a + b2 ; }
clearly means that
a. floatl has already been declared
b. floatl has not yet been defined
c. at line 21 in power_i.h, you are trying to use floati (not just in name, but in size)
> this is a strange problem!
no, it is not. it is a very commom problem that occurs when you try to use something
without having defined it.
Last edited by vijayan121 : Nov 10th, 2007 at 11:04 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Problem in Uploading Files using Register Global on/off (PHP)
- Upload problem of large files in Win 2003 (Windows NT / 2000 / XP / 2003)
- Problem in Regards to Local Files- Please Help ASAP. (Windows NT / 2000 / XP / 2003)
- Several problem with video files (Windows Software)
- Simple problem regardingform elements (ASP)
- Annoying problem with moving files (Windows NT / 2000 / XP / 2003)
- Win XP Startup Problem (Windows NT / 2000 / XP / 2003)
- Access to 'Lost' files (Windows NT / 2000 / XP / 2003)
- Does Samba send deleted files to a recycle bin? (*nix Software)
- problems wid cpp files (C++)
Other Threads in the C++ Forum
- Previous Thread: ran into a wall
- Next Thread: Not waiting for input during loop



Linear Mode