0

Sorry my bad English first of all.

I just want to use a class globally in my project but i receive some error. I researched and tried similar titles but didnt work. Maybe i could not do.

code.h


#ifndef CODE_H_
#define CODE_H_

class sinif
{

   public:  void doSomeThing()
            {
                 /*
                 ...
                 */
            }
   private:

};

sinif A;

#endif

Form1.h


//that is main form

#include "code.h"
#include "b.h"

namespace project
{

          /*
          ...

          A.doSomeThing();   // it works  
          */    
}

b.h


//that is second mini form

#include "code.h"

extern sinif A;

namespace project
{
           /*
          ...

          A.doSomeThing();  //it didn't work
          */    
}
Hayrullah Cansu
  • 262
  • 5
  • 14
  • You cannot declare a class *extern*. The C++ compiler is a single-pass compiler, you have to do the normal thing you need to do and separate the declaration from the definition. The method that contains the statement must be moved in a .cpp file, one that can #include the required .h files. – Hans Passant Aug 24 '14 at 11:23
  • Is it like yellow answer in http://stackoverflow.com/questions/7923392/c-extern-class-declaration ? – Hayrullah Cansu Aug 24 '14 at 11:33
  • 1
    Your variable needs to be defined in exactly one compilation unit -- you pretty much always want to put the definition in a .cpp file, not a header, for that reason. (The `extern` declaration does belong in a header, that part is ok.) – Ben Voigt Aug 29 '14 at 18:29
  • 1
    "I receive some error" is not the way to ask a useful question. Tell us what the error is, or we'll never be able to help. – Ben Voigt Aug 29 '14 at 18:29
  • @Hans: based on the code, it looks like he means to "extern" *an object of class type*, not the class itself. – Ben Voigt Aug 29 '14 at 18:31
  • Can you write a sample basicly, please. – Hayrullah Cansu Aug 29 '14 at 18:32

0 Answers0