Non class type error

Hi,

Im getting this error when i try and compile a library i've written. Can anyone shed any light on it?

error:

 In function 'void loop()':
error: request for member 'getButton' in 'Nunchuck', which is of non-class type 'Nunchuck ()()'

.h:

// ensure this library description is only included once
#ifndef Nunchuck_h
#define Nunchuck_h

// include types & constants of Wiring core API
#include <WProgram.h>

// include types & constants of Wire ic2 lib
#include <../Wire/Wire.h>



class Nunchuck
{
  public:
      void nunchuck();
      int getButton(char button);
      
      
  private:
      void Send(byte Value);
      void initialize();
      byte nunchuckDecodeByte(byte x);
      int outBuffer[6];
      int cnt;
      int z_button;
      int c_button;
};

extern Nunchuck Wii;
#endif

sketch:

#include <Wire.h>
#include <Nunchuck.h>

Nunchuck Nunchuck();

void setup() {
Serial.begin(9600);  
}

void loop() {
  int button_value = Nunchuck.getButton("c");
  Serial.print("ButtonC: ");
  
  Serial.println(button_value);
  delay(100);
}

Thanks!

If this void nunchuck(); is supposed to be the constructor it needs to be Nunchuck();

Be sure that the Nunchuck.cpp looks like this:

#include "Nunchuck.h"

int Nunchuck::getButton(char button){
}

:slight_smile:

[edit]
I think it would be easier if the function Send gets renamed to send, it makes for a more consistend API
[/edit]

Nunchuck Nunchuck();

How much none would a Nunchuck chuck, if a Nunchuck could chuck none?

You can't declare a variable with the name of a type. Just as you can't say int int = 3; you can't do what you've done.

Nunchuck chuck;
Nunchuck chuck = Nunchuck(args); // if constructor args are required

Given the last line of your header file, a better name for your global instance is Wii.

Nunchuck Wii;

I'm not sure if this is the cause of the problem, but in your class definition, you have the type of the argument to 'getButton' as a 'char', but you call the member function with a string. Your call should look like this:

int button_value = chuck.getButton('c');

Note the single quotes.