Hello, I am trying to create functions outside the class they are used in and am getting errors about duplicate creations. is this not how you create functions outside of classes? by defining them inside and then doing the work outside?
You should put the function definitions (line 18-30) inside a source file (.cpp). If you put it inside the header and the header is included in more than one source file you will get an error because the functions gets defined multiple times. Only inline functions are allowed to be defined more than once. Functions that are defined inside the class body are automatically inline so that was why you didn't get an error before.
you cannot define an instance variable inside a class, u call a constructor for that.
@vlad from moscow:
usage of inline functions is something different, inline functions are expanded at the place of call so the flow is faster, its used in some rare cases of optimsation.
please go though it before u suggest blindly.
even ur code will throw up compilation error because of above mentioned reason.
@anirudh sn
@vlad from moscow:
usage of inline functions is something different, inline functions are expanded at the place of call so the flow is faster, its used in some rare cases of optimsation.
please go though it before u suggest blindly
"is something different" with what? I doubt that you understood my post. To escape the error of breaking the ODR-rule you can either define a function in a class as Peter87 pointed out that to make it inline or define it outside the class but specifying inline function specifier. In this case there is no need to modify rest modules of the project.
So I do not see any great sense in your improper remark "please go though it before u suggest blindly".
This remark has more sense apllied to you yourself.
Also I advice you to read new C++ Standard about data class member definitions.
thank u, good to know, another bull shit optimization, the compiler puts that automatically in the constructor, ISO guys can pat their their backs for this, then wats wrong with the code by blucky ???
> another bull shit optimization, the compiler puts that automatically in the constructor, ISO guys...
Who are you? There used to be a resident Java bigot sometime back, whose diatribes were characterised by fanaticism and ignorance, in roughly equal measure. If you are the same person, under a pseudonym now, may I direct you to the "lounge" section. You may have admires there, people who relish your fulminations.
Regardless of the spat over use of inline, Peter87 is correct - unless there's an overriding reason not to, you should put the implementation of your methods into a .cpp file that is compiled once and then linked by other translation units.
While there are sometimes reasons to include the complete method implementation in the header file, it's usually best not to. Yes, I'm keeping it simple for a beginner.