をチャーないようにと言い変換エラー、ヘッダファイルそれは "char型*" からの変換はこれが私の.hある
#ifndef KINGDOM_H_
#define KINGDOM_H_
namespace westeros {
class Kingdom {
public:
char m_name[32];
int m_population;
};
void display(Kingdom pKingdom[], int kingdomElement, char nameOfKingdom);
}
#endif
これは私の.cpp、ソースファイル
#include <iostream>
#include "kingdom.h"
using namespace std;
namespace westeros{
void display(Kingdom pKingdom[], int kingdomElement, char nameOfKingdom){
cout << "------------------------------" << endl;
for (int i = 0; i < kingdomElement; i++) {
**if(pKingdom[i].m_name == nameOfKingdom){** //it's giving me error right here, visual studio underlining red line below == sign saying operand types are incompatible
cout << "Searching for kingdom " << pKingdom[i].m_name << " in Westeros " << endl;
cout << "------------------------------" << endl;
cout << pKingdom[i].m_name << ", population " << pKingdom[i].m_population << endl;
}
else {
cout << "------------------------------" << endl;
cout << "Searching for kingdom " << nameOfKingdom << " in Westeros " << endl;
cout << "------------------------------" << endl;
cout << nameOfKingdom << " is not part of Westeros." << endl;
cout << "------------------------------" << endl;
}
}
}
}
です
、これが私のメインのファイルは、それ
#include <iostream>
#include "kingdom.h"
using namespace std;
using namespace westeros;
int main(void)
{
int count = 0; // the number of kingdoms in the array
Kingdom* pKingdoms = nullptr;
//allocating dynamic memory
pKingdoms = new Kingdom[count];
display(pKingdoms, count, "Mordor");
cout << endl;
display(pKingdoms, count, "The_Vale");
cout << endl;
delete[]pKingdoms;
pKingdoms = nullptr;
return 0;
}
を呼び出そうとしています
問題の可能性がある人は誰でも見つかりますか?
あなたは 'char'と文字列の違いについて混乱しています。 'char'は単一の文字(例えば、文字)です。 – aschepler
ああ、char nameOfKingdomは1文字しか受け入れることができないことを意味しますか?どのタイプを使用するのですか? –
ascheplerが言ったことの大きなヒント: "charと文字列の違い[。]"この文の2つの型は、すでに 'char'が動作していないことを発見しました。 – user4581301