3

I get an illegal indirection error at generateCSVHeader(*file4);.

function declaration:

void generateCSVHeader(QFile * file);

function use:

str="MyData.csv";
QFile file4(str);
generateCSVHeader(*file4);

when I drop the dereference designator, it gives me a cannot convert QFIle to QFile * error.

moesef
  • 4,641
  • 16
  • 51
  • 68

1 Answers1

3

You should pass pointer to your QFile object (which is an address) instead of passing the object itself (dereferencing is irrelevant, because it is used only with pointers, not objects). To get an address of your object, you should use the & operator. So you have to invoke your function like this:

generateCSVHeader(&file4)

Also, you may consider using references instead of pointers.

nameless
  • 1,969
  • 11
  • 34
  • 1
    Declare your function like this: `void generateCSVHeader(QFile & file);`. Then just pass your object to it: `generateCSVHeader(file)`. References work like constants pointers which are dereferenced automatically. – nameless Jan 26 '13 at 03:45