CPP

포스트: 32|조회수: 0|ORGANIZATION
Items

Posts

32 posts

[C++] C2440 : const char[]에서 char*로 변환할 수 없습니다 에러에 관하여

프로그래밍 일지|2019년 1월 17일

[그림 1] C2440 ERROR 문자열 리터럴을 사용하기 위해서 char* 형태의 변수를 선언했을 때 [그림 1]과 같은 에러가 발생한다.에러의 내용은 "aa"라는 문자열은 const(상수)값인데 변수에 그 값을 집어넣으려고 하니 에러가 발생한다는 것이다. 도대체 이런 에러가 왜 발생하는 걸까? 이런 에러가 발생하는 이유를 MSDN에서는 다음과 같이 설명하고 있다. C2440 can be caused if you attempt to initialize a non-const char* (or wchar_t*) by using a string literal in C++ code, when the compiler conformance option /Zc:strictStrings is set.

[C++] 월별 날짜 수, 윤년 계산기 코드

프로그래밍 일지|2019년 1월 16일

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576#pragma once#include using namespace std; class Date { int month; int day; int year; public: Date(int m, int d, int y) : month(m), day(d), year(y) { if (month == 2 && day == 29) cout << "incorrect

[C++] dynamic_cast

프로그래밍 일지|2019년 1월 15일

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include "pch.h"#include using namespace std; class Parent {public: virtual void Print() {}};class Child_1 : public Parent {public: virtual void Print() { cout << "Child_1 is OK" << endl; }}; class Child_2 : public Parent {public: virtual void Print() { cout

[C++] return by reference

프로그래밍 일지|2019년 1월 15일

123456789101112131415161718192021222324252627#include using namespace std; struct job { char jname[20]; int role; double pay;}; const job & findJob(job &j); int main(){ job j1 = { "DB Design", 1, 100.33 }; job j2; j2 = findJob(j1); cout << j2.role; return 0;} const job & findJob(job &j){ j.role = 2; j.pay += 200.234; return j;