Pointer to Boolean

I have declared a variable
 
bool* newData = false;

and I try to use it in a function
1
2
3
4
void setBoolean(bool* newData)
{
  if (this == true) &newData = true;
}


My compiler tells me, "expression must be a modifiable value".

So, it's wrong. Please, where is it wrong?

Thanks
Pointer to Boolean - why?

expression must be a modifiable value


You probably meant *newData = true;

At the moment you a taking the address again with the &, while * dereferences.

if (this == true)


Always true.
closed account (SECMoG1T)
also you are binding your pointer to a temporary object, you need to allocate some memory if you need to manipulate it later.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bool* newData = false;  newData points to a temporal object
  

void setBoolean(bool* newData)
{
  if (true) 
     *newData = true;///  this would lead to a segvault
}

///allocate some memory
bool* newData =new bool(false);

void setBoolean(bool* newData)
{
  if ( true) 
     *newData = true;///a valid operation
 }
Right :+)

So the whole function is pointless now?
andy1992's declaration
///allocate some memory
bool* newData =new bool(false);
seems to have fixed it. I can't actually tell yet, there is some more development to do, but it compiles okay.

Thanks
Topic archived. No new replies allowed.