Question
객체를 만들려고합니다. Question
클래스 인하지만 오류 받고 있어요 : 나는 여기객체를 만들 때 오류가 발생했습니다.
유형 <int, Questions>
의 multimap
에 넣어 수 있도록 내가 객체를 만들기 위해 노력하고있어
Error 1 error C2440: 'initializing' : cannot convert from
Questions *
toQuestions
은 내 코드입니다 :
#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'은 이런 식으로'Question * q1'을 선언하는 포인터 여야합니다. – imreal
모든 문자열이 가장 오른쪽 값이 될 것입니다. 또한 포인터가 필요한 경우'new'를 사용하지 마십시오. 대신 스마트 포인터를 사용하십시오. – chris
q9 문자열에서 큰 따옴표를 사용하는 방식이 잘못되었습니다. 검투사 ""를'검투사 \ "로 대체하십시오. –