я получаю ошибку:Objective-C пользовательский класс
VertexPoint.m:12:1: Type of property 'color' ('GLfloat *' (aka 'float *')) does not match type of instance variable '_color' ('float [4]')
и
VertexPoint.m:12:1: Type of property 'position' ('GLfloat *' (aka 'float *')) does not match type of instance variable '_position' ('float [3]')
Что я должен сделать, чтобы решить это?
Вот код:
//
// VertexPoint.m
#import <Foundation/Foundation.h>
#import "VertexPoint.h"
@implementation VertexPoint
- (id)init {
self = [super init];
if (self) {
_position[0] = 1;
_position[1] = 2;
_position[2] = 3;
_color[0] = 1;
_color[1] = 2;
_color[2] = 3;
_color[3] = 4;
}
return self;
};
- (GLfloat *)x {
return &_position[0];
};
- (GLfloat *)y {
return &_position[1];
};
- (GLfloat *)z {
return &_position[2];
};
- (GLfloat *)r {
return &_color[0];
};
- (GLfloat *)g {
return &_color[1];
};
- (GLfloat *)b {
return &_color[2];
};
- (GLfloat *)a {
return &_color[3];
};
- (void)setPosition:(GLfloat *)pos {
for (NSUInteger i = 0; i < 3; i++)
_position[i] = pos[i];
};
- (void)setColor:(GLfloat *)col{
for (NSUInteger i = 0; i < 4; i++)
_color[i] = col[i];
};
@end
и
// VertexPoint.h
//
#import <Foundation/Foundation.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
@interface VertexPoint : NSObject
{
GLfloat _position[3];
GLfloat _color[4];
}
@property(nonatomic,readwrite) GLfloat *position;
@property(nonatomic,readwrite) GLfloat *color;
@property(nonatomic,readwrite) GLfloat *x;
@property(nonatomic,readwrite) GLfloat *y;
@property(nonatomic,readwrite) GLfloat *z;
@property(nonatomic,readwrite) GLfloat *r;
@property(nonatomic,readwrite) GLfloat *g;
@property(nonatomic,readwrite) GLfloat *b;
@property(nonatomic,readwrite) GLfloat *a;
- (GLfloat *)x;
- (GLfloat *)y;
- (GLfloat *)z;
- (GLfloat *)r;
- (GLfloat *)g;
- (GLfloat *)b;
- (GLfloat *)a;
-(void)setColor:(GLfloat *)col;
-(void)setPosition:(GLfloat *)pos;
@end
ОБНОВЛЕНО РАЗ (2)
Новые ч и м файлы:
#import <Foundation/Foundation.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
@interface VertexPoint : NSObject
{
GLfloat _position[3];
GLfloat _color[4];
}
@property(nonatomic,readwrite) GLfloat *position;
@property(nonatomic,readwrite) GLfloat *color;
@property(nonatomic,readonly) GLfloat x;
@property(nonatomic,readonly) GLfloat y;
@property(nonatomic,readonly) GLfloat z;
@property(nonatomic,readonly) GLfloat r;
@property(nonatomic,readonly) GLfloat g;
@property(nonatomic,readonly) GLfloat b;
@property(nonatomic,readonly) GLfloat a;
- (GLfloat)x;
- (GLfloat)y;
- (GLfloat)z;
- (GLfloat)r;
- (GLfloat)g;
- (GLfloat)b;
- (GLfloat)a;
-(void)setColor:(GLfloat *)col;
-(void)setPosition:(GLfloat *)pos;
@end
и
#import <Foundation/Foundation.h>
#import "VertexPoint.h"
@implementation VertexPoint
- (id)init {
self = [super init];
if (self) {
_position[0] = 1.0f;
_position[1] = 1.0f;
_position[2] = 1.0f;
_color[0] = 1.0f;
_color[1] = 1.0f;
_color[2] = 1.0f;
_color[3] = 1.0f;
}
return self;
};
- (GLfloat)x {
return _position[0];
};
- (GLfloat)y {
return _position[1];
};
- (GLfloat)z {
return _position[2];
};
- (GLfloat)r {
return _color[0];
};
- (GLfloat)g {
return _color[1];
};
- (GLfloat)b {
return _color[2];
};
- (GLfloat)a {
return _color[3];
};
- (void)setPosition:(GLfloat *)pos {
for (NSUInteger i = 0; i < 3; i++)
_position[i] = pos[i];
};
- (void)setColor:(GLfloat *)col{
for (NSUInteger i = 0; i < 4; i++)
_color[i] = col[i];
};
@end
Исходное сообщение об ошибке все еще существует.
Почему все ваши свойства 'GLfloat' определены как указатели? 'GLfloat' - простой примитивный тип. – rmaddy
не так ли? Это первый раз, когда я должен сделать что-то подобное, пожалуйста, научи меня :) – MegaX
Когда он говорит: «Не соответствует типу переменной экземпляра« _color »(« float [4] ») и« не соответствует типу переменной экземпляра '_position' ('float [3]') «это расстроено, потому что вы пытаетесь заменить float указателем на float. Все эти звездочки, вероятно, не нужны при объявлении и возврате GLfloat. Если вам нужно использовать указатели, продолжайте и делайте это. Но вы не можете заменить float указателем float и притвориться, что это тот же тип данных. – Dare