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

//this is intl.h

# ifndef _header_i
#define _header_i

#include "floatl.h"
#include <iostream>
using namespace std;

class intl
{
..
..
};
#endif
//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

> functions are defined in 5 different headers
what do these look like?

> a header allheaders.h which include all the header files
in what order?

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 !:idea:
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

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

//********* 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_
Comments
it's done with some kind of patience .i judge him based upon his previous replys.there was knowledge and patience in every one of them

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?

> 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 struct A { int i ; double d ; }; and class 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:

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 ;
}

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

This question has already been answered. Start a new discussion instead.