By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,923 Members | 1,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,923 IT Pros & Developers. It's quick & easy.

Pointer problems

P: n/a
Hi all,
I'm using the following code, but there's a problem somewhere.

// Typedef af 8 arrays af 7 pointere til ints
#include <iostream>
using namespace std;

int main()
{
typedef int ((*test)[7])[8];

int a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7;

// array af 7 pointere til ints

int* data[] = {&a, &b, &c, &d, &e, &f, &g};

test p;

p[0] = &data;
p[1] = &data;
p[2] = &data;
p[3] = &data;
p[4] = &data;
p[5] = &data;
p[6] = &data;
p[7] = &data;

return 0;

}

I'm gettin the following error messages:

g++ 593-2.cpp
593-2.cpp: I function 'int main()':
593-2.cpp:23: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:24: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:25: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:26: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:27: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:28: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:29: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:30: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'

Can any of you tell me whats wrong?

--

// Morten - www.mortenvp.dk
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Morten V Pedersen wrote:
I'm using the following code, but there's a problem somewhere.

// Typedef af 8 arrays af 7 pointere til ints
A pointer to int:

typedef int *pint;

An array of 7 pointers to int

typedef int *sevenpint[7];

An array of 8 array of 7 pointers to int

typedef int *eightarraysofsevenpint[8][7];

#include <iostream>
using namespace std;

int main()
{
typedef int ((*test)[7])[8];
Wrong dimensions.

typedef int *test[8][7];

int a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7;

// array af 7 pointere til ints
int* data[] = {&a, &b, &c, &d, &e, &f, &g};

test p;

p[0] = &data;
p[1] = &data;
p[2] = &data;
p[3] = &data;
p[4] = &data;
p[5] = &data;
p[6] = &data;
p[7] = &data;
If 'p' is an array of arrays, then every element if it is an array.
p[0] is an array, p[1] is an array, etc. Arrays cannot be assigned to.

Nor can they be initialised from a single variable ('data' decays to
a pointer to a pointer to int if used in an expression). You need

test p = { { &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g } };

return 0;

}

I'm gettin the following error messages:

g++ 593-2.cpp
593-2.cpp: I function 'int main()':
593-2.cpp:23: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:24: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:25: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:26: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:27: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:28: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:29: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:30: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'

Can any of you tell me whats wrong?


Plenty.

V
Jul 23 '05 #2

P: n/a
Victor Bazarov wrote:
Morten V Pedersen wrote:
I'm using the following code, but there's a problem somewhere.

// Typedef af 8 arrays af 7 pointere til ints

A pointer to int:

typedef int *pint;

An array of 7 pointers to int

typedef int *sevenpint[7];

An array of 8 array of 7 pointers to int

typedef int *eightarraysofsevenpint[8][7];

#include <iostream>
using namespace std;

int main()
{
typedef int ((*test)[7])[8];

Wrong dimensions.

typedef int *test[8][7];

int a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7;

// array af 7 pointere til ints
int* data[] = {&a, &b, &c, &d, &e, &f, &g};

test p;

p[0] = &data;
p[1] = &data;
p[2] = &data;
p[3] = &data;
p[4] = &data;
p[5] = &data;
p[6] = &data;
p[7] = &data;

If 'p' is an array of arrays, then every element if it is an array.
p[0] is an array, p[1] is an array, etc. Arrays cannot be assigned to.

Nor can they be initialised from a single variable ('data' decays to
a pointer to a pointer to int if used in an expression). You need

test p = { { &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g } };

return 0;

}

I'm gettin the following error messages:

g++ 593-2.cpp
593-2.cpp: I function 'int main()':
593-2.cpp:23: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:24: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:25: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:26: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:27: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:28: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:29: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:30: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'

Can any of you tell me whats wrong?


Plenty.

V


Thx for the help, i got it working now..

--

// Morten - www.mortenvp.dk
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.