Pages: [1]   Go Down
Author Topic: Struct problem  (Read 206 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#include "MyClass.h"

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

void loop()
{
 
}

In my MyClass.cpp is:

Code:
#include "MyClass.h"

MyClass::MyClass()
{
}

And in MyClass.h is:

Code:
#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!
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
MyClass obj();  //change this

to

Code:
MyClass obj;
Logged

From Idea To Invention

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awsome that works, thanks Cybernetician!

Out of curiosity what is the difference between:

MyClass obj();

And

MyClass obj;

?

Thanks again,

Dan
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 53
Posts: 1792
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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:
MyClass obj;

This declares a variable.
Logged


Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for late reply i was litle busy in my code

"pYro_65 explains it well"
Logged

From Idea To Invention

Pages: [1]   Go Up
Jump to: