-1

I have a problem with the next code, I get the error: invalid type argument of unary '*' (have 'int'). If I write int *content that allows the code to run, but I have to write int=content and change the code *((ptab->content)+pC1+17), I tried but I can't fix the error.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <stdio.h>
#include <Windows.h>

using namespace std;

struct box{
    int content;
};
struct box *ptab;

int pC1=5;

int main (){
    ptab=new struct box[64];

    if (*((ptab->content)+pC1+17)==0) {
        pC1=pC1+17;
    }
    cout<<pC1<<endl;
}

I have to pass from pointers to poninters to struct arrays, this code is an example, because the original code has 23000 lines.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <stdio.h>
#include <Windows.h>

using namespace std;

int *box;

int pC1=5;

int main (){
    box=new int[64];

    if (*(box+pC1+17)==0){
                                        pC1=pC1+17;
                                    }
    cout<<pC1<<endl;
}
dilver
  • 55
  • 2
  • 11
  • You can't dereference this expression: `((ptab->content)+pC1+17)` – 101010 Nov 15 '15 at 00:01
  • What are you actually trying to do in this code? What would the correct output be? (There are multiple ways to get this to compile, but it's not clear from your question which one you want - they have different meanings.) – pmdj Nov 15 '15 at 00:04
  • I'd love to give a better recommendation than "Rethink what you are attempting here", but I have no clue what you're trying to do. A better explanation of the goal of this code may provide better results. – user4581301 Nov 15 '15 at 00:25
  • I have other code for a game, that code has 23000 lines and I have to pass from pointers to pointers to struct arrays – dilver Nov 15 '15 at 00:30
  • I edit the question and I write the code with pointers, thank you =) – dilver Nov 15 '15 at 00:36

1 Answers1

0

With *((ptab->content)+pC1+17), an easier way to say it is ptab[pC1+17].content [the latter compiles and produces 22 as output]. Did you mean that or ptab->content + pC1 + 17 [which produces 5]?

Craig Estey
  • 30,627
  • 4
  • 24
  • 48