월 24,200원
5개월 할부 시다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 해결됨홍정모의 따라하며 배우는 C++
배열의 크기에 대한 질문이요
int a[3];cout << sizeof(a) <<endl; cout << sizeof(a[3]) <<endl;이 둘의 출력결과가 다른이유는 무엇인가요??
- 미해결홍정모의 따라하며 배우는 C++
5.4 goto
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.안녕하세요 강의를 수강 중인 학생입니다. 다름이 아니라 만약 if문을 이용해서 어떤 조건을 만든 다음, 해당 조건이 성립하면 밑의 코드들을 몇 개 뛰어넘고 다른 코드로 바로 이동하기 위해서는 goto 말고 다른 방법이 있을까요??
- 미해결홍정모의 따라하며 배우는 C++
9.5 증감연산자에서 예제 실행이 이상해요
결과값이 위 그림과 같이 32758로 이상하게 나옵니다그런데 아래와 같이 friend 함수에서 입력 파라미터에서 const와 reference를 없애니 정상적으로 나옵니다.
- 미해결홍정모의 따라하며 배우는 C++
생성자의 매개변수 유무와 괄호 유무
안녕하세요 16분 경 해당 캡처사진 코드 관련 질문드립니다. 18번째 줄의 생성자의 매개변수를 둘다 초기화 하시고int main 함수에서Fraction one_third (); 라고 쓰면 안된다고 하셨습니다'파라미터(매개변수)가 없기 때문에 괄호를 삭제해주어야한다' 라고 하셨는데이 경우는 생성자의 매개변수가 없는 것이 아니라 보내는 인자값이 없는 것 아닌가요?생성자에는 매개변수가 2개가 존재하는데..헷갈리네요 감사합니다.
- 미해결홍정모의 따라하며 배우는 C++
6:36 `void registerStudent(const Student & const student_input)`error
안녕하세요, const를 두번 넣으니까 아래와 같은 에러가 나옵니다. 이렇게 바꾸면 문제가 없습니다. const Student & student_inputconst가 2개 필요한 이유가 따로 있을까요?/usr/bin/clang++ -std=c++17 -fcolor-diagnostics -fansi-escape-codes -g /Users/user/Documents/cpp/10-3/10-3.cpp -o /Users/user/Documents/cpp/10-3/10-3 In file included from /Users/user/Documents/cpp/10-3/10-3.cpp:4: /Users/user/Documents/cpp/10-3/Lecture.h:26:40: error: 'const' qualifier may not be applied to a reference void assignTeacher(const Teacher & const teacher_input) ^ /Users/user/Documents/cpp/10-3/Lecture.h:31:42: error: 'const' qualifier may not be applied to a reference void registerStudent(const Student & const student_input)code# Lecture.h #pragma once #include <vector> #include "Student.h" #include "Teacher.h" class Lecture { private: std::string m_name; Teacher teacher; std::vector<Student> students; public: Lecture(const std::string & name_in) : m_name(name_in) {} ~Lecture() { // do NOT delete teacher // do NOT delete students } void assignTeacher(const Teacher & const teacher_input) { teacher = teacher_input; } void registerStudent(const Student & const student_input) { students.push_back(student_input); // vector에 넣는다 } void study() { std::cout << m_name << " Study " << std::endl << std::endl; for (auto & elem : students) // for each에서 ref로 받아야 값 변환 가능 elem.setIntel(elem.getIntel() + 1); } friend std::ostream & operator << (std::ostream & out, const Lecture & lecture) { out << "Lecture name : " << lecture.m_name << std::endl; out << lecture.teacher << std::endl; for (auto elem : lecture.students) out << elem << std::endl; return out; } };
- 미해결홍정모의 따라하며 배우는 C++
11분 코드 질문
안녕하세요 하기 코드 질문드립니다int sumTo(int sumto){ if (sumto <= 0) return 0; else if (sumto <= 1) return 1; else return sumTo(sumto - 1) + sumto; }에서 굵게 표시한if(sumto < = 1) return 1; 이 굳이 필요한 부분인가요?~return 0은 재귀함수 중단을 위해 꼭 필요한 것이란 걸 알겠습니다만~return 1은 어떤 이유에서 추가하셨는지 궁금해서 여쭤봅니다. 미리 답변 감사드립니다.
- 미해결홍정모의 따라하며 배우는 C++
19.4 [14:04] std::lock_guard, std::scoped_lock 컴파일 오류
#include <iostream> #include <thread> #include <atomic> #include <mutex> #include <chrono> using namespace std; mutex mtx; int main() { int shared_memory(0); //atomic<int> shared_memory(0); auto count_func = [&]() { for (int i = 0; i < 1000; ++i) { this_thread::sleep_for(chrono::milliseconds(1)); //shared_memory++; //shared_memory.fetch_add(1); /*mtx.lock(); shared_memory++; mtx.unlock();*/ //std::lock_guard lock(mtx); //std::scoped_lock lock(mtx); shared_memory++; } }; thread t1 = thread(count_func); thread t2 = thread(count_func); thread t3 = thread(count_func); thread t4 = thread(count_func); t1.join(); t2.join(); t3.join(); t4.join(); cout << "After" << endl; cout << shared_memory << endl; return 0; } Debug 모드로 진행시 std::lock_guard랑 scoped_lock이 정상적으로 compile되고 작동이 되는데,Release 모드로 변경하니 해당 lock_guard는 missing template이 뜨고, scoped_lock은 member가 존재하지 않는다고 뜨는데어떤 점이 문제일까요?..교수님 강의에서는 Release 모드에서도 잘 작동하는 거로 보였습니다.
- 미해결홍정모의 따라하며 배우는 C++
auto operator<=>(const MyInt& rhs) const = default; 이 코드처럼 "=default" 가 몬가요? 어느강의 부분에 설명이 되어 있나요?
강의에 있었던거 같기도 하고 기억이 잘 안나는데,, 혹시 강의 어느 챕터를 봐야 하는지 아시는 분 계실까요?어디서 비슷한 문법을 본 것 같은데 기억이 잘 나질 않네여
- 미해결홍정모의 따라하며 배우는 C++
코드 조금 바꿔서 작성 중 에러
안녕하세요, 아래처럼 코드 짜니까 에러가 발생하는데 왜 그럴까요? 교수님 강의에서 관련된 내용을 들었던 것 같은데 못 찾겠네요;;class IntList { private: static int m = 10; int m_list[m] = { 1, 2, 3, 4, 5, }; ... >> error: non-const static data member must be initialized out of line static int m = 10;
- 미해결홍정모의 따라하며 배우는 C++
todo가 뭘 하라는 건지 모르겠어요
use divide and conquer(future로 하는 것) starategy for std::thread와 atomic 사용해서 구현해보기 가 첫번째 숙제인데.. 이게 뭘 하라는 건지 잘 모르겠어요. 혹시 강의 어디를 보면 참고 코드가 있을까요? 두번째 promise사용해서 구현하는 것은 해보았습니다~ 감사합니다.
- 미해결홍정모의 따라하며 배우는 C++
10:59 멤버 함수로서 연산자 오버로딩
멤버함수로서 연산자 오버로딩을 할 때는 무조건 parameter가 하나이어야 하는거죠? (이게 그냥 rule인걸까요? 이해가 아니라 외워야 하는...)standalone 함수일 때는 연산자 오버로딩할 때 parameter 갯수 상관없는 것 같은데 맞나요?
- 미해결홍정모의 따라하며 배우는 C++
7분쯤 friend 사용
아무리 생각해도 friend사용해서 이점을 보려면 아래처럼 코드를 짜야할 것 같은데 제가 맞나요? 교수님께서 바쁘셔서 깜빡하시고 standalone function을 friend로 넣어두기만 하신 것으로 보이는데 맞을까요? friend Cents operator+(const Cents &c1, const Cents &c2) { return Cents(c1.m_cents + c2.m_cents); }
- 미해결홍정모의 따라하며 배우는 C++
변수와의 만남 수업질문 입니다.
1.3 변수와의 첫 만남 수업을 듣고 있습니다. 수업 내용 (22:06) Release를 without debugging을 실행하면 0의 값으로 출력이 된다고 했는데 제가 연습을 해보니 실행이 안됩니다. 제가 실행 했던 부분중에서 어떤것들이 잘 못되었는지 궁금합니다.
- 미해결홍정모의 따라하며 배우는 C++
22분 코드 질문 (&, && 관련)
if ((items_flag & opt2) && !(items_flag & opt1))에서 &&는 논리연산자이므로(items_flag & opt2), !(items_flag & opt1)두항 모두 0000 0000이 아니기만 하면 true로 동작하는건가요? 미리 답변 감사드립니다.
- 미해결홍정모의 따라하며 배우는 C++
마지막 퀴즈 질문 (0110 >> 2)
cout << std::bitset<4>(0110 >> 2) << endl;으로 넣어 출력했더니답이 0010으로 나옵니다 (10진수는 18로 출력됨)답은 0110 >> 2 하면 0001이 되어 1아닌가요?왜 0010(18)이 출력되는지 궁금하여 여쭤봅니다. 미리 답변 감사드립니다.
- 미해결홍정모의 따라하며 배우는 C++
솔루션 익스프롤러 질문이 있습니다
강의를 듣다 보면 cpp 파일과 솔루션 익스프롤러 창이 분리가 되어있는걸 볼수 있는데요. 선생님과 같이 솔루션 익스프롤러를 오른쪽 구석으로 이동하고 싶은데 어떻게 해야 하나요?
- 미해결홍정모의 따라하며 배우는 C++
클린 솔루션 관련
동영상에서 26:08 에 나오는 클린 솔루션을 눌렀는데 디버그 폴더에 파일들이 삭제가 안되고그냥 남아 있습니다. 왜 삭제가 안되는지 궁금합니다. VS2022 버전입니다.
- 미해결홍정모의 따라하며 배우는 C++
ofs.write((char*)&num_data, sizeof(num_data)); 질문
const unsigned num_data = 10; ofs.write((char*)&num_data, sizeof(num_data)); for (int i = 0; i < num_data; ++i) ofs.write((char*)&i, sizeof(i)); 여기서 같은 write함수인데,,, 위에꺼는 그냥 파일공간만 확보하는 건가요? 아래꺼는 실제로 쓰는거구요?이 부분이 너무 이해가 안되네요... ofs.write((char*)&num_data, sizeof(num_data));<- 이라인이 하는 역할을 잘 모르겠네요...같은 맥락에서 ifs.read((char*)&num_data, sizeof(num_data)); <- 이 라인의 역할과 처음 num_data를 0으로 초기화 시켜서 이 변수가 디버그를 돌려보니 10으로 바뀌더라고요.. 어떻게 해서 그렇게 되는건지.. ifs.read((char*)&num, sizeof(num));<- 이줄은 그럼 그 다음 주소로부터 4바이트씩 읽어오는 것인지.. 아니면 메모리에 이만한 공간을 할당하는 과정인지 궁금하네요..
- 미해결홍정모의 따라하며 배우는 C++
왜 안될까요 컴파일러 문제일까요?
헤더만 사용하면 항상 에러가 나는데 왜인지 잘 모르겠습니다.directory 구조는8-8_haeder - main.cpp - calc.cpp - Calc.h하지만 빌드하면 아래와 같은 에러가 뜹니다Starting build... /usr/bin/clang++ -std=c++17 -fcolor-diagnostics -fansi-escape-codes -g /Users/user/Documents/cpp/8-8_header/main.cpp -o /Users/user/Documents/cpp/8-8_header/main Undefined symbols for architecture arm64: "Calc::add(int)", referenced from: _main in main-0ed3f2.o "Calc::mul(int)", referenced from: _main in main-0ed3f2.o "Calc::sub(int)", referenced from: _main in main-0ed3f2.o "Calc::print()", referenced from: _main in main-0ed3f2.o "Calc::Calc(int)", referenced from: _main in main-0ed3f2.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Build finished with error(s).Mac m1인데 컴파일러 문제일까요?아래는 코드입니다.//calc.cpp #include "Calc.h" using namespace std; Calc::Calc(int init_value) : m_value(init_value) {} Calc& Calc::add(int value) { m_value += value; return *this; } Calc& Calc::mul(int value) { m_value *= value; return *this; } Calc& Calc::sub(int value) { m_value -= value; return *this; } void Calc::print() { cout << m_value << endl; } //Calc.h #pragma once #include <iostream> class Calc { private: int m_value; public: Calc(int init_value); Calc& add(int value); Calc& mul(int value); Calc& sub(int value); void print(); }; //main.cpp #include <iostream> #include "Calc.h" using namespace std; int main() { Calc cal(10); cal.add(10).sub(1).mul(2).print(); }
- 미해결홍정모의 따라하며 배우는 C++
getter 코드 2개다 동일하게 작동할까요? (코드 첨부)
class Point { private: int x; int y; public: Point(int i = 0, int j = 0) : x(i), y(j) {} // Point(int i = 0, int j = 0) // { // x = i; // y = j; // } int getX() const {return x;} const int& getX2() {return x;} };위애서 getX() 랑 getX2() 둘다 동일한 걸까요?