Jump to content

Singleton: Difference between revisions

→‎{{header|C}}: expand a bit
(Adding C)
(→‎{{header|C}}: expand a bit)
Line 148:
void JumpOverTheDog(int numberOfTimes)
{ ...
lazyDog.isAnnoyed = TRUE;
}
int PlayFetchWithDog( float weightOfStick )
{ ...
if(weightOfStick < lazyDog.max_stick_weight){...
}</lang>
Code using the singleton includes the header and cannot create a
struct sDog as the definition is only in the C source (or other header privately included by the silly.c source). Only the functions declared in the header may be used externally.
<lang c>...
#include "silly.h"
...
/* code using the dog methods */
JumpOverTheDog( 4);
retrieved = PlayFetchWithDog( 3.1);
...</lang>
 
=={{header|C++}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.