클래스 및 클래스 에서 파생 된 클래스 player
의 벡터를 포함 하는 변수가 있습니다 .Resource
Name
ID
코드를 컴파일 할 때 문제가 있고 컴파일 중에 다음 오류가 나타납니다.
resources.h(27): note: 'Resources &Resources::operator =(const Resources &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'IdClass &IdClass::operator =(const IdClass &)'
idclass.h(11): note: 'IdClass &IdClass::operator =(const IdClass &)': function was implicitly deleted because 'IdClass' has a data member 'IdClass::id' of const-qualified non-class type
idclass.h(4): note: see declaration of 'IdClass::id'
기본적으로 제가 Resources.cpp
한 것은 플레이어 벡터의 리소스를 초기화하는 함수가 있다는 것입니다. 일부 답변을 위해 StackOverflow를 둘러 보지 않았지만 유용한 답변을 보지 못했기 때문에이 오류로 인해 이상했습니다. 이 링크 는 닫혔지만 const를 비 const 값으로 변경하는 것이 필요한지 확실하지 않습니다.
여기에 코드가 있습니다.
Resources.h에서
#include "NameClass.h"
#include "IdClass.h"
#include "settings.h"
class PlayerClass;
class Resources : public NameClass, public IdClass
{
public:
/*Sets the name and id*/
Resources(string n, const short identifier):NameClass(n), IdClass(identifier){}
static void InitializeResourceContainer(PlayerClass& player){
// playerInv is a struct
// rssContainer is a vector<Resources>
// name_x and id_x comes from settings.h which is #defined
player.playerInv.rssContainer.push_back(Resources(name_Stone, id_Stone));
player.playerInv.rssContainer.push_back(Resources(name_Wood, id_Wood));
player.playerInv.rssContainer.push_back(Resources(name_Plastic, id_Plastic));
player.playerInv.rssContainer.push_back(Resources(name_Thatch, id_Thatch));
player.playerInv.rssContainer.push_back(Resources(name_Fabric, id_Fabric)); // this is line 27
// plus a lot of resources
}
}
IdClass.h에서
class IdClass
{
const short id;// line 4
public:
/*Sets the id*/
IdClass(const short idToSet);
/*returns the id*/
short GetId() const;
}; // line 11
IdClass.cpp에서
#include "IdClass.h"
/*Sets the id*/
IdClass::IdClass(const short idToSet) : id(idToSet)
{
}
/*returns the id*/
short IdClass::GetId() const { return id; }
이것은 제가 작업중인 코드의 작은 부분입니다. 더 많은 설명이나 코드가 필요하면 아래 주석에 몇 가지를 줄 수 있습니다.
편집 1 : 출력 뒤에 오류 코드를 넣는 것을 잊은 것 같습니다. 또한 Visual Studio 2017을 사용하고 있습니다.
Error C2280 'Resources &Resources::operator =(const Resources &)': attempting to reference a deleted function f:\visual studio\2017\vc\tools\msvc\14.10.25017\include\xutility 2310
IdClass.h 에서 변수를에서 const short
로 변경하면 short
내 클래스 중 하나에서 링커 오류가 발생합니다.
Error LNK1120 1 unresolved externals
Error LNK2001 unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > FileManager::playerName" (?playerName@FileManager@@0V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) ArchizzleGame C:\Users\CraftedGaming\Documents\Visual Studio 2017\Projects\ArchizzleGame\ArchizzleGame\FileManager.obj 1
두 명의 댓글 작성자가 연결 한 두 개의 스레드는 그다지 도움이되지 않았습니다.
내가하려는 것은 Resources.h에서 IdClass.h로 id 값을 가져 오는 것입니다.
const short를 short로 변경하여 첫 번째 문제를 해결했습니다. 이것이 마지막 컴파일 오류 였으므로 연결 단계로 이동했습니다. 이로 인해 두 번째 (관련되지 않은!) 오류, 선언이 있지만 정의가없는 FileManager 클래스의 정적 문자열 playerName이 노출되었습니다.
C ++에서는 다음과 같은 정적을 "선언"하는 것으로 충분하지 않습니다.
class A
{
static int a;
}
또한 "정의"하거나 일부 .cpp 파일에 다음 줄을 추가하여 본문을 제공해야합니다 (여러 번 다시 정의 될 수 있으므로 .h가 아님).
int A::a = 0;
그러나 플레이어 이름이 FileManager 클래스의 정적 멤버가되기를 원하는지 잘 모르겠습니다. 이것은 많은 파일 관리자가 모두 동일한 플레이어 이름을 공유한다는 것을 의미합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다