c++에서 lnk2005 오류가 났습니다.

wkqkrhdclrl의 이미지

각 파일별로 따로 작성하였습니다.

//Circle.cpp
#include
#include "Circle.h"
#include
using namespace std;

void Circle::setCircle(string name, int radius) {
this->name = name;
this->radius = radius;
}
double Circle::getArea() {
return 3.14*radius*radius;
}
string Circle::getName() {
return this->name;
}

//Circle.h

#ifndef CIRCLE_H
#define CIRCLE_H
#include
#include
using namespace std;

class Circle {
int radius;
string name;
public:
void setCircle(string name, int radius);
double getArea();
string getName();
};
#endif;

//CircleManager.h
#pragma once
#ifndef CIRCLE_MANAGER_H
#define CIRCLE_MANAGER_H
#include
#include
#include "Circle.h"

class CircleManager {
Circle* p;
int size;
public:
CircleManager(int size);
~CircleManager();
void searchByName();
void searchByArea();

};
#endif;

//CircleManager.cpp
#include
using namespace std;
#include "CircleManager.h"
#include

void Circle::setCircle(string name, int radius) {
this->name = name;
this->radius = radius;
}

CircleManager::CircleManager(int size) {
string name;
int radius;

p = new Circle[size];
this->size = size;
for (int i = 0; i < size; i++) {
cout << "원 " << i + 1 << "의 이름과 반지름 >> ";
cin >> name >> radius;
p[i].setCircle(name, radius);
}
}

CircleManager::~CircleManager() {
delete[] p;
}

void CircleManager::searchByName() {
string name = "";
cout << "검색하고자 하는 원의 이름 >> ";
cin >> name;
for (int i = 0; i < size; i++) {
if (name == p[i].getName()) {
cout << name << "의 면적은 " << p[i].getArea() << endl;
}
}
}

void CircleManager::searchByArea() {
int area;
cout << "최소 면적을 정수로 입력하세요 >> ";
cin >> area;
cout << area << "보다 큰 원을 검색합니다.\n";
for (int i = 0; i < size; i++) {
if (area < p[i].getArea()) {
cout << p[i].getName() << "의 면적은 " << p[i].getArea() << ",";
}
}
}

//main.cpp
#include
#include
#include "CircleManager.h"
using namespace std;

int main(void) {
int r, n, cnt = 0;
cout << "원의 개수 >> ";
cin >> n;
CircleManager circleManager = CircleManager(n);
circleManager.searchByName();
circleManager.searchByArea();

}

익명 사용자의 이미지

1. "lnk2005"이 무슨 뜻인지 검색해본다
2. "기호가 두 번 이상 정의되었습니다." 라는 설명을 읽고 이해한다.
3. ("기호"가 뭔 뜻인지는 모르겠더라도) 코드 전체적으로 동일한 이름이 두 번 정의된 곳이 있는지 꼼꼼히 살펴본다.

번외1. 헤더에서 using namespace std;를 쓰는 건 정말 좋지 않습니다.

번외2. 질문글을 올릴 땐 자기 코드가 잘 올라갔는지 정도는 확인을 하고 넘어가야지요.

익명 사용자의 이미지

아래 코드가 두번 정의되어 있다고 오류가 나는데요?

void Circle::setCircle(string name, int radius) {
    this->name = name;
    this->radius = radius;
}
wkqkrhdclrl의 이미지

수정했습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.