Skip to main content

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what OOObject Orientation terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completedcompletely different. Be careful - here be dragons.

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what OO terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completed different. Be careful - here be dragons.

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what Object Orientation terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completely different. Be careful - here be dragons.

deleted 26 characters in body
Source Link
Brendan Long
  • 54.6k
  • 21
  • 154
  • 194

[Significantly edited]

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what OO terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completed different. Be careful - here be dragons.

[Significantly edited]

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what OO terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completed different. Be careful - here be dragons.

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what OO terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completed different. Be careful - here be dragons.

Complete re-write following comments.
Source Link
Douglas Leeder
  • 53.5k
  • 9
  • 100
  • 138

a)[Significantly edited]

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

b)Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

cb) static member function - what OO terms a static method means that you. Lives inside a class. You call itthis with the class rather than through an object instance.

These two different static function definitions are completed different. Be careful - here be dragons.

a) It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-)

b) a static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

c) a static method means that you call it with the class rather than through an object instance.

[Significantly edited]

First: It's generally a bad idea to include a .cpp file in another file - it leads to problems like this :-) The normal way is to create separate compilation units, and add a header file for the included file.

Secondly:

C++ has some confusing terminology here - I didn't know about it until pointed out in comments.

a) static functions - inherited from C, and what you are talking about here. Outside any class. A static function means that it isn't visible outside the current compilation unit - so in your case a.obj has a copy and your other code has an independent copy. (Bloating the final executable with multiple copies of the code).

b) static member function - what OO terms a static method. Lives inside a class. You call this with the class rather than through an object instance.

These two different static function definitions are completed different. Be careful - here be dragons.

Source Link
Douglas Leeder
  • 53.5k
  • 9
  • 100
  • 138
Loading