我在西班牙語網站(http://trucosinformaticos.wordpress.com/2010/12/12/programacion-orientado-a-objetos-en-c/)中發現了這種黑客攻擊。C中的類(不是C++)
我要創建C(不是C++)一個 「類」,但是當我編譯,我得到下一個錯誤:
source.c(25): warning C4047: 'function' : 'Car' differs in levels of indirection from 'Car *'
source.c(25): warning C4024: 'changeYears' : different types for formal and actual parameter 1
這是我的代碼:
#include <string.h>
typedef struct Car* Car;
// class Car
// {
struct Car
{
int years;
//char model[100];
};
void changeYears(Car this, int years)
{
this->years = years;
}
// }
int main(void)
{
Car my_cars[10];
//nombrar(mis_alumnos[0], "Pepito");
changeYears(&my_cars[0], 6); // My car has now 6 years
return 0;
}
你做出大量的代碼通過隱藏背後的typedef指針混亂。我建議不要這樣做。 –
[項目爲「OO在C」](http://www.cs.rit.edu/~ats/books/ooc.pdf) –
請問一個新的問題,而不是編輯現有的一個。 – merlin2011