Author Topic: CC: not work with local var 'this' - why?  (Read 3266 times)

Offline veector

  • Single posting newcomer
  • *
  • Posts: 2
CC: not work with local var 'this' - why?
« on: October 25, 2017, 01:34:22 pm »
fo() - var 'this' = no code completion.
bar() - var 'self' = code completion work good.
Why?

Code
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int one;
    int two;
} cc_t;

void fo(cc_t *this)
{
        this->one = 1; // No code completion.
        this->two = 2; // No code completion.
}

void bar(cc_t *self)
{
        self->one = 1; // Code completion work.
        self->two = 2; // Code completion work.
}



int main()
{
    printf("Hello world!\n");
    return 0;
}


Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: CC: not work with local var 'this' - why?
« Reply #1 on: October 25, 2017, 01:41:42 pm »
Because "this" is a keyword in C++, so please change "this" to other word.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline veector

  • Single posting newcomer
  • *
  • Posts: 2
Re: CC: not work with local var 'this' - why?
« Reply #2 on: October 25, 2017, 01:48:58 pm »
Because "this" is a keyword in C++, so please change "this" to other word.
Thank you for your response.
I will use var "self".