Go Down

Topic: Struct problem (Read 269 times) previous topic - next topic

Hi All,

Whilst trying to use an instance of a struct in my class I keep getting this error when I compile:

error: request for member 'Position' in 'obj', which is of non-class type 'MyClass ()()'

In my .imo file I have:

Code: [Select]
#include "MyClass.h"

void setup()
{
  MyClass obj();
  obj.Position.X = 10;
  obj.Position.Y = 10;
}

void loop()
{
 
}


In my MyClass.cpp is:

Code: [Select]
#include "MyClass.h"

MyClass::MyClass()
{
}


And in MyClass.h is:

Code: [Select]
#ifndef MyClass_h
#define MyClass_h

struct MyStruct
{
  int X;
  int Y;
};

class MyClass
{
public:
MyStruct Position;

MyClass();
protected:
};

#endif


I can't see anything obvious that's wrong with it, all I'm trying to do is set the property of a struct instance but get this error, any ideas?


Thanks!

Cybernetician

Code: [Select]

MyClass obj();  //change this


to

Code: [Select]

MyClass obj;
From Idea To Invention

Awsome that works, thanks Cybernetician!

Out of curiosity what is the difference between:

MyClass obj();

And

MyClass obj;

?

Thanks again,

Dan

pYro_65

Code: [Select]
MyClass obj();

This is actually declaring a function called 'obj' that returns a 'MyClass', which is why the error said "MyClass ()()" which is a function type, similar to a function pointer.

Code: [Select]
MyClass obj;

This declares a variable.

Cybernetician

Sorry for late reply i was litle busy in my code

"pYro_65 explains it well"
From Idea To Invention

Go Up