Some trouble with vectors and classes

Jun 5, 2013 at 12:40am
O hai hoomans of ceeplusspluss

I have some code and I dont know whats wrong with it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #include "Startup.h"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
StartProfile::question::question(){
	a = rand() % 12 + 1;
	b = rand() % 12 + 1;
	answer = a*b;
};
void StartProfile::setup(){
	vector<StartProfile::Player> players;
	vector<StartProfile::Player> pref;
	vector<string> names;
	pref.reserve(4);
	players.reserve(4);
	string xplayercount;
	cout << "Hello, and welcome to MyMultiplication BETA 1.0!\n";
	sleep(1);
	cout << "This is a 1 to 4 player multiplication game for all ages!\n";
	sleep(1);
	cout << "Enter number of players: ";
	getline(cin, xplayercount);
	int playercount;
	stringstream(xplayercount) >> playercount; 	
	for (int i = 1;i <= playercount; i++) {
		cout << "Player " << i <<", please enter your name: ";
		getline(cin, pref[i-1].name);
		players.push_back ((pref[i-1]).name);
		cout << "\nAlright, " << players[i-1].name << "! You are ready to go.\n";
	};
	cout << "Everyone is checked in! Lets start!";
};
void StartProfile::askandrecord(StartProfile& player, int count){
	cout << player.Player.name << ", you are starting!\n";
	sleep(1);
	cout << '3\n';
	sleep(1);
	cout <<  '2\n';
	sleep(1);
	cout << '1\n';
	sleep(1);
	cout << "GO\n";
	
	
};

The point of the code is:

a) Get number of players
b) Make vector storing player info
c) Generate questions

When I compile, I get four errors
Line Location Startup.cpp:39: error: no matching function for call to '__gnu_debug_def::vector<StartProfile::Player, std::allocator<StartProfile::Player> >::push_back(std::string&)'

Line Location Startup.cpp:44: error: prototype for 'void StartProfile::askandrecord(StartProfile&, int)' does not match any in class 'StartProfile'

Line Location Startup.cpp:45: error: invalid use of 'class StartProfile::Player'

Line Location Startup.h:34: error: candidate is: void StartProfile::askandrecord(StartProfile::Player&, int)

Can I have some help please?

Sincerly,

Mr. N00b
Jun 5, 2013 at 7:52am
the error pretty much says it all:

on line 30: you pass a string while a Player was expected
on line 35: not StartProfile but Player was expected
Topic archived. No new replies allowed.