Created
December 4, 2015 06:40
-
-
Save LaughingSun/abad548d043baa8934cf to your computer and use it in GitHub Desktop.
C++11 private static * char and char[implied length] test cases (because my old school sh!t couldn't wrap my head around it until I was able to isolate it)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "private-static-const-char-array.hpp" | |
const char | |
PrivateStaticConstCharArray::private_static_const_char_array[] | |
= "A bit of text used to test private static const char array in a " \ | |
"class declaration/definition"; | |
PrivateStaticConstCharArray::PrivateStaticConstCharArray ( ) | |
{ | |
} | |
const char * | |
PrivateStaticConstCharArray::getter () const | |
{ | |
return private_static_const_char_array; | |
} | |
int | |
main ( int argc, char * argv[] ) | |
{ | |
PrivateStaticConstCharArray thing; | |
std::printf( "thing.getter() => \"%s\"\n", thing.getter() ); | |
// std::printf( "PrivateStaticConstCharArray::private_static_const_char_array => \"%s\"\n" | |
// , PrivateStaticConstCharArray::private_static_const_char_array ); | |
/* produces the following at compile time: | |
private-static-const-char-array.cpp: In function ‘int main(int, char**)’: | |
private-static-const-char-array.cpp:5:1: error: ‘const char PrivateStaticConstCharArray::private_static_const_char_array [93]’ is private | |
PrivateStaticConstCharArray::private_static_const_char_array[] | |
^ | |
private-static-const-char-array.cpp:29:38: error: within this context | |
, PrivateStaticConstCharArray::private_static_const_char_array ); */ | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PRIVATE_STATIC_CONST_CHAR_ARRAY_HPP | |
#define PRIVATE_STATIC_CONST_CHAR_ARRAY_HPP | |
#include <cstdlib> | |
#include <cstdio> | |
class | |
PrivateStaticConstCharArray | |
{ | |
private: | |
static const char private_static_const_char_array[]; | |
public: | |
PrivateStaticConstCharArray ( ); | |
const char * getter () const; | |
}; | |
#endif // PRIVATE_STATIC_CONST_CHAR_ARRAY_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "private-static-const-star-char.hpp" | |
const char * | |
PrivateStaticConstStarChar::private_static_const_star_char | |
= "A bit of text used to test private static const star char in a " \ | |
"class declaration/definition"; | |
PrivateStaticConstStarChar::PrivateStaticConstStarChar ( ) | |
{ | |
} | |
const char * | |
PrivateStaticConstStarChar::getter () const | |
{ | |
return private_static_const_star_char; | |
} | |
int | |
main ( int argc, char * argv[] ) | |
{ | |
PrivateStaticConstStarChar thing; | |
std::printf( "thing.getter() => \"%s\"\n", thing.getter() ); | |
// std::printf( "PrivateStaticConstStarChar::private_static_const_star_char => \"%s\"\n" | |
// , PrivateStaticConstStarChar::private_static_const_star_char ); | |
/* produces the following at compile time: | |
private-static-const-star-char.cpp: In function ‘int main(int, char**)’: | |
private-static-const-star-char.cpp:5:1: error: ‘const char* PrivateStaticConstStarChar::private_static_const_star_char’ is private | |
PrivateStaticConstStarChar::private_static_const_star_char | |
^ | |
private-static-const-star-char.cpp:29:37: error: within this context | |
, PrivateStaticConstStarChar::private_static_const_star_char ); */ | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PRIVATE_STATIC_CONST_STAR_CHAR_HPP | |
#define PRIVATE_STATIC_CONST_STAR_CHAR_HPP | |
#include <cstdlib> | |
#include <cstdio> | |
class | |
PrivateStaticConstStarChar | |
{ | |
private: | |
static const char * private_static_const_star_char; | |
public: | |
PrivateStaticConstStarChar ( ); | |
const char * getter () const; | |
}; | |
#endif // PRIVATE_STATIC_CONST_STAR_CHAR_HPP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment