가변 길이 템플릿
Posted by 천천히, 꾸준히
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include template void print(T arg) { std::cout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include template void print(T arg) { std::cout
구조체와 클래스 1 2 3 4 5 6 7 8 9 10 11 12 13 struct Point { int x, y; }; int main() { Point p = { 1,2 }; return 0; } cs 구조체는 구조체를 만들어준 =뒤, main()에서 p를 선언하고 구조체를 초기화해주면 된다. 여기서 struct 대신 class를 써주면 클래스가 된다. 그런데 클래스로 바꿔주면 컴파일 과정에서 오류가 발생한다. 클래스와 구조체 모두 데이터를 묶어주는 역할을 하는데 오류가 발생하는 이유는 무엇일까 그 이유는 구조체와 클래스의 기본 접근제어 지시자가 다르기 때문이다. 구조체의 경우 접근제어 지시가를 따로 선언하지 않으면 모든 변수와 함수가 public으로 선언되고 클래스의 경우 private로 선언된다. ..
소스코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include #include using namespace std; long sum(vector &a) { long sum = 0; for (int i = 0; i > n; vector a(n); for (int i = 0; i > a[i]; } cout
소스코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #include using namespace std; void self() { int sum[10000] = { 0 }; int res = 0; for (int i = 1; i = 10 && i
소스코드 1234567891011121314151617181920212223242526#include using namespace std; int main() { int index = 0; int n, i, r; cin >> n; for (i = 0; i
소스코드 12345678910111213141516171819202122232425262728#include using namespace std; int main() { int apart[15][15]; apart[0][0] = 1; int t, a, b = 0; for (int i = 1; i a >> b; cout
소스코드 123456789101112131415161718192021222324252627#include using namespace std; int main() { int index = 1; // 몇 개의 방을 지나는지 체크 int i = 0; // 단계의 수 int lev = 1; // 총 방의 수 int n; cin >> n; while (true) { lev = lev + i * 6; if (n
1234567891011121314151617181920212223242526#include int main() { int arr[1000]; int temp; int n; std::cin >> n; for (int i = 0; i > arr[i]; } for (int i = 0; i