할당 연산자를 멤버 함수로 오버로드하여 문자열을 인수로 사용하여 해당 값을 A
, 현재 개체에 할당하려고합니다. 아래의 의견에 오류를 게시했습니다.연산자를 오버로드하는 방법 =
누군가 내가 뭘 잘못하고 있다고 말할 수 있습니까? 나는 그것이 매개 변수와 관련이 있으며, 아마도 정의 안에있는 코드라고 생각한다.
내가 올바르게 선언 있는지 확실하지 않습니다,하지만 나는 이런 식으로 선언 :
WORD operator=(const string& other);
그리고 나는 이런 식으로 정의 : 도움이된다면 여기
WORD WORD::operator=(const string& other) //<---not sure if I did the parameters Correctly
{
(*this) = other;
return (*this);
}
전체 파일입니다 :
#include <iostream>
using namespace std;
#pragma once
class alpha_numeric //node
{
public:
char symbol; //data in node
alpha_numeric *next;//points to next node
};
class WORD
{
public:
WORD() : front(0) {length=0;}; //front of list initially set to Null
WORD(const WORD& other);
bool IsEmpty();
int Length();
void Insert(WORD bword, int position);
WORD operator=(const string& other);
private:
alpha_numeric *front; //points to the front node of a list
int length;
};
WORD WORD::operator=(const string& other) //<---not sure if I did the parameters Correctly
{
(*this) = other;
return (*this);
}
"읽을 수없는 혼란"을 게시하십시오. –
오류 오류 LNK2005 : "public : class WORD __thiscall WORD :: operator = (클래스 std :: basic_string, 클래스 std :: allocator > const") @@ QAE? AV0 @ ABV? $ basic_string @ DU? $ char_traits @ D @ std @@ V? $ allocator @D @ 2 @@ std @@@ Z) 이미 word.obj에 정의되어 있습니다. \t C : \ Users \ Mike \\ System \ Data Structures Assignment 2 \ word_driver.obj –
Mike
오류 오류 LNK2019 : 해결되지 않은 외부 기호 "public : __thiscall WORD :: WORD (클래스 단어 const &)"(0WORD @ @ QAE @ ABV0 @@ Z) 함수에서 참조 된 : public : class WORD __thiscall WORD :: operator = (class std :: basic_string, class std :: allocator > const " ?? 4WORD @@ QAE? AV0 @ ABV? $ basic_string @ DU? $ char_traits @ D @ std @@ V? $ allocator @ D @ 2 @@ std @@@ Z) \t C : \ Users \ Mike \ Desktop \ School 프로그램 \ 데이터 구조 지정 2 \ 데이터 구조 지정 2 \ word.obj –
Mike