본문 바로가기

c++programming7

C++ 오류 : 여러 번 정의된 기호가 있습니다. 상속생성.obj에 이미 정의되어 있습니다. 오류 : 여러 번 정의된 기호가 있습니다. xxx.obj에 이미 정의되어 있습니다. LNK1169 LNK2005 자바를 해보니 프로젝트가 패키지 의미 인줄 알았다. C++에서는 한 프로젝트안에 파일 분할의 개념으로 헤더파일, cpp파일 등으로 나눌 수 있다. 그렇지만 한 프로제트 내에 main 문을 2개 이상 두면 위와 같은 오류 발생 int main(), void main() 2019. 1. 25.
C++ 다형성 가상함수 이해 간단 코드 다형성 virtual 가상함수 #include#includeusing namespace std; class A {public:virtual void f() { cout 2019. 1. 23.
C++ 상속inheritance, (순수)가상함수(pure)virtual function, 추상 클래스(abstract class), overriding, 바인딩 가상 함수 정의 virtual 기본 클래스 멤버 함수의 선언;virtual int computeSalary() { return 1500000; } 가상 함수 구현 Code 예시 #include #include using namespace std; //추상 클래스class Employee{private:string name;int id; public:Employee();Employee(string name, int id);~Employee();void setName(string name);string getName();void setId(int id);int getId(); virtual int computeSalary() { return 1500000; } //가상 함수, 보다 직관적으로 함수를 호출};.. 2019. 1. 18.
C++ 상속inheritance, derived class, 오버라이드(overriding) - Power C++ p565 LAB 상속inheritancederived class 선언class 파생 클래스 명 : 접근 지정자 기본 클래스 명{파생 클래스에 추가할 멤버 선언}; 클래스의 큰 장점인 '상속(inheritance)' '캡슐화(Encapsulation)' '다형성' protected : 파생클래스의 함수에서 기본 클래스의 protected멤버에 접근할 수 있다. 상속방법:class Student : public Human 기본 클래스의 public 멤버 -> 파생 클래스의 public 멤버기본 클래스의 protected멤버 -> 파생 클래스의 protected멤버기본 클래스의 private멤버 -> 파생 클래스의 private멤버 멤버 함수 오버라이드오버라이드(overriding) : 파생 클래스의 함수가 기본 클래스의 함.. 2019. 1. 17.
C++ operator+ 연산자 오버로드(operator overloading) ,friend ostream& operator / friend istream& operator (스트림) 1. operator overloading 객체간의 연산을 위한 기능연산자 오버로드(operator overloading) 이라고 한다. 경우 1) 인수가 한 개리턴 값의 형 operator 연산자(인수);Complex operator+(Complex c); //이항 연산자를 멤버 함수로 오버로드 연산결과 +연산자의 왼쪽변수 오른쪽 변수Complex Complex::operator+(Complex c); //코드{Complex com(0,0);com.real = real + c.real;com.imag = imag + c.imag;return com;} 경우 2) 인수가 두 개friend 리턴 값의 형 operator 연산자 (인수1, 인수2);friend Complex operator+ (int c1,.. 2019. 1. 16.
C++ 기초 static변수 최다 최소 구하기 / 여러 번 정의된 기호가 있습니다.LNK1169 LNK2005 Student.h #pragma once#include #include using namespace std; class Student { string name; int kor, math, eng, avr; public:static int count;Student();double getAvr();string getName();static int getcount() { return count; }~Student() {}}; Student.cpp #include "Student.h"#include using namespace std; Student ::Student(){cout > name;cout > kor;cout > math;cout > eng;++count;//생성시 증가} double Student .. 2019. 1. 16.
C++ coding training function, array, class[c++ 코딩연습: 함수, 배열, 클래스, 프로토타입 헤더 분리] 문제(요구사항):메시지를 3개 정도 입력해서 연결이 된 상태(connect) 에서 play()로 메시지 출력 play(2) 해당 위치의 메시지movePos 출력할 위치 옮기기, msgdelete() 해당 위치 메시지 제거 disconnect() 시 play()호출 하면 출력 불가 메시지-제시된 main 함수는 기본적인 테스트 용 이므로, 메인 문 추가코드 작성 aam.h#include using namespace std; class AAM {string text; public:void connect();void record();int play();int play(int n);int getMsgNum();void movePos(int n);void msgdelete();void disconnect();};.. 2019. 1. 12.