Skip to content

Instantly share code, notes, and snippets.

@endavid
Created May 21, 2024 10:17
Show Gist options
  • Save endavid/697c3ae8805f3e5634cd87f889bf6502 to your computer and use it in GitHub Desktop.
Save endavid/697c3ae8805f3e5634cd87f889bf6502 to your computer and use it in GitHub Desktop.
static vs extern
#include "header.h"
std::string A::name = "David";
std::string surname = "Gavilan";
#include <string>
class A {
public:
static std::string name;
};
extern std::string surname;
#include <iostream>
#include "header.h"
// g++-13 -std=c++17 -Wall -Wextra -o main *.cpp
int main() {
std::cout << "Hello " << A::name << " " << surname << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment