我正在嘗試製作一個Question
對象。 Question
作爲類,但我得到一個錯誤是:嘗試製作對象時出錯
Error 1 error C2440: 'initializing' : cannot convert from
Questions *
toQuestions
我試圖讓一個對象,我就可以把它放到類型<int, Questions>
這裏的multimap
是我的代碼:
#include <iostream>
#include "Questions.h"
using namespace std;
Questions::Questions() {}
Questions::Questions(string question,string correctAnswer, string wrongAnswer1,string wrongAnswer2,string wrongAnswer3) {}
void Questions::questionStore() {
Questions q1 = new Questions("Whats the oldest known city in the world?", "Sparta", "Tripoli", "Rome", "Demascus");
string q2 = ("What sport in the olympics are beards dissallowed?", "Judo", "Table Tennis", "Volleyball", "Boxing");
string q3 = ("What does an entomologist study?", "People", "Rocks", "Plants", "Insects");
string q4 = ("Where would a cowboy wear his chaps?", "Hat", "Feet", "Arms", "Legs");
string q5 = ("which of these zodiac signs is represented as an animal that does not grow horns?", "Aries", "Tauris", "Capricorn", "Aquarius");
string q6 = ("Former Prime Minister Tony Blair was born in which country?", "Northern Ireland", "Wales", "England", "Scotland");
string q7 = ("Duffle coats are named after a town in which country?", "Austria", "Holland", "Germany", "Belgium");
string q8 = ("The young of which creature is known as a squab?", "Horse", "Squid", "Octopus", "Pigeon");
string q9 = ("The main character in the 2000 movie ""Gladiator"" fights what animal in the arena?", "Panther", "Leopard", "Lion", "Tiger");
map.insert(pair <int, Questions>(1, q1));
map.insert(pair <int, string>(2, q2));
// map.insert(pair<int,string>(3, q3));
for (multimap <int, string, std::less <int> >::const_iterator iter = map.begin(); iter != map.end(); ++iter)
cout << iter->first << '\t' << iter->second << '\n';
}
'q1'應該是一個指針,用這種方式聲明'Questions * q1'。 – imreal
所有的字符串都將是最右邊的值。另外,如果你需要一個指針,請不要使用'new'。改用智能指針。 – chris
你在q9字符串中使用雙引號的方式是錯誤的。用'\「Gladiator \」'替換'「」角鬥士「」''。 –