quick question!

Stupid question I'm sure, took a break from my learning of c++ to focus on a few other CS relates subjects.

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
  #include <iostream>
#include <string>

using namespace std;

struct Teams
{
    string name;
    string type;
    int power;
};
void name_teams (Teams names [], int num)
    {
    for (int i = 0; i < num; i++)
    {
        cout <<"Player, what is your team name?"<<endl;
        cin >>names[i].name;

    }
    }

int main()
{
    Teams names;
    name_teams (names, 2 );
    cout <<names[0].name;
    cout <<names[1].name;

}


debug is :
1
2
3
4
5
6
7
8

mingw32-g++.exe -Wall -fexceptions -g  -c C:\Users\Mcodes\Desktop\game\main.cpp -o obj\Debug\main.o
C:\Users\Mcodes\Desktop\game\main.cpp: In function 'int main()':
C:\Users\Mcodes\Desktop\game\main.cpp:25:26: error: cannot convert 'Teams' to 'Teams*' for argument '1' to 'void name_teams(Teams*, int)'
C:\Users\Mcodes\Desktop\game\main.cpp:26:19: error: no match for 'operator[]' in 'names[0]'
C:\Users\Mcodes\Desktop\game\main.cpp:27:19: error: no match for 'operator[]' in 'names[1]'
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 0 warning(s) (0 minute(s), 0 second(s))


merely trying to freshen up on pointers, structures, arrays, functions and how they can work together but it seems I've grown quite rusty in my c++ coding.

If somebody could help tell me where I'm wrong in this that would be great, I'm trying to create two structures and have them named by input
Line 24 introduces a single Teams object. Both the function and lines 26-27 expect (2 member) array.

See http://www.cplusplus.com/doc/tutorial/arrays/
Hey thanks, wow I thought I had tried that... shankksh :)

Could you help with one thing also. do you know how I would code this with pointers to functions vs the pointers being disguised in the syntax?

if you know what I mean?
disguised in the syntax?

what do you mean by that?
closed account (48T7M4Gy)
pointers to functions vs the pointers being disguised in the syntax


use typedef?
http://en.cppreference.com/w/cpp/language/typedef
what do you mean by that?

I was mistaken. I didn't understand that (par exemple)

void funct ( int array [] )

just basically "converts" to

void funct ( int *array )

in c++

Just trying to get a solid understanding but I'm definitely going to focus on pointers a bit more now.

Thanks again fellas.
Topic archived. No new replies allowed.