1

Topic: include context.h

Explain please
I create certain context.h

#ifndef CONTEXT
#define CONTEXT
class context {
public:
void run ();
}
void context:: run () {
}
#endif CONTEXT

We collect it is received:
Undefined symbols for architecture x86_64:context:: run referenced from:
At the same time if to import
void context:: run () {
}
In cpp-shku - that all is good.
After all in the beginning h-nika costs #ifndef
Like #include should  connect exactly 1 time
Thanks.

2

Re: include context.h

semen.s.semen;

#ifndef CONTEXT
#define CONTEXT
class context {
public:
void run () {;}
}
#endif CONTEXT

Here so it is necessary.

3

Re: include context.h

semen.s.semen;
More precisely here so
#ifndef CONTEXT
#define CONTEXT
class context {
public:
void run () {;}
}; //forgot a semicolon.
#endif CONTEXT

4

Re: include context.h

It

#ifndef CONTEXT
#define CONTEXT
...
#endif CONTEXT

It is possible to replace on

#pragma once

On a subject

#pragma once
class context {
public:
void run () {
...
}
};

5

Re: include context.h

Thanks for an explanation
Explain  - why my variant does not work
I want to understand as the collector works

6

Re: include context.h

semen.s.semen wrote:

We collect it is received:
Undefined symbols for architecture x86_64:context:: run referenced from:

You drive, other error should be.
Problem in that you define the same function many times, but you do not declare it inline neither it is explicit, nor it is implicit.

7

Re: include context.h

MasterZiv;
You again hurry up.

8

Re: include context.h

semen.s.semen wrote:

I Want to understand as the collector

works
Hardly you will understand by this example, From + a-trouble +, than operation of the collector here is faster.
Roughly speaking, function determination in several obektnikah/libraries is forbidden on the classic.
And here in With ++ there is an indulgence - functions inline are resolved.

9

Re: include context.h

AmKad wrote:

MasterZiv;
You again hurry up.

In sense?

10

Re: include context.h

MasterZiv, it seems to me. That at the HARDWARE the semicolon is passed
But I am rare on With I write, .. As the compiler perceived code .. - I do not know

11

Re: include context.h

At me the declaration in 1 place
too in 1 place
Simply both of them in 1 file
All works if I  shift in cpp - a file

12

Re: include context.h

semen.s.semen wrote:

Brrrr
At me the declaration in 1 place
too in 1 place
Simply both of them in 1 file
All works if I  shift in cpp - a file

No, you are wrong. Think why.

13

Re: include context.h

MasterZiv wrote:

You drive, other error should be.

I  also received yesterday such error
The class name only another was
Here laid out the changed class name and a method
The principle remained the same

14

Re: include context.h

semen.s.semen;
Give we begin with error report specification.

wrote:

Undefined symbols for architecture x86_64:context:: run referenced from:

15

Re: include context.h

MasterZiv wrote:

Is not present, you are wrong. Think why.

It is wrong in what?
Where 2nd declaration? Where 2nd ?
File too 1

16

Re: include context.h

MasterZiv wrote:

semen.s.semen;
Give we begin with error report specification.
it is passed...

In an original error was
Undefined symbols for architecture x86_64
Further  in which class names and methods were read

17

Re: include context.h

MasterZiv wrote:

it is passed...
In sense?

About the passed semicolon already told. Therefore with it a mentioned below variant . And that you told about repeated determination f-ii - simply hurried.

context.h wrote:

#ifndef CONTEXT
#define CONTEXT
class context {
public:
void run ();
};
void context:: run () {
}
#endif CONTEXT

main.cpp wrote:

#include "context.h"
int main ()
{
context ctx;
ctx.run ();
}

18

Re: include context.h

semen.s.semen;
The problem at you should be that you include context.h in SOME source files.
Then the error should be something of type

 multiple definition of symbol void context:: run 

Instead of as at you where this character is not defined generally any time.
Other variant can be, if you do not include this context.h in one source file.
Then there would be such error as you resulted but then also the class would not be declared, use you it could not.
Anyway, if a problem did not solve, spread the code on https://hastebin.com/or analogs.

19

Re: include context.h

MasterZiv wrote:

the Problem at you should be that you include context.h in SOME source files.

So after all
#ifndef CONTEXT
#define CONTEXT
It is used
It will be real 1

20

Re: include context.h

AmKad wrote:

About the passed semicolon already told. Therefore with it a mentioned below variant . And that you told about repeated determination f-ii - simply hurried.

It is obvious that the semicolon at it already there was, differently it would not reach an assembly phase, compilation would give an error.

21

Re: include context.h

MasterZiv wrote:

Instead of as at you where this character is not defined generally any time.

All at me is defined
And all works even if context.h is included in many source codes and  lies in separate cpp-shke

22

Re: include context.h

semen.s.semen wrote:

it is passed...
So after all
#ifndef CONTEXT
#define CONTEXT
It is used
It will be real 1

Will be 1  if you include this title some times in the same initial unit.
I speak about its switching-on in DIFFERENT units.

23

Re: include context.h

MasterZiv wrote:

it is passed...
Will be 1  if you include this title some times in the same initial unit.
I speak about its switching-on in DIFFERENT units.

All works even if context.h is included in many source codes and  lies in separate cpp-shke

24

Re: include context.h

semen.s.semen wrote:

it is passed...
All at me is defined
And all works even if context.h is included in many source codes and  lies in separate cpp-shke

Then give the code.
To your conjectures to listen not interesting.
You tell one, and actually at you another.

25

Re: include context.h

MasterZiv wrote:

....
It is obvious that the semicolon at it already there was, differently it would not reach an assembly phase, compilation would give an error.

To whom it is obvious, and to whom is not present
Well and neither about the environment, nor about parameters of the assembly it is told nothing
The author separately the compiler and  from command line can or FAR launches))) .. Error presence on a compile phase, does not mean that it could not reach an assembly phase))) and to collect is banal what  old files)))