initalize a constructor in a class.

Hi, I want to initialize a twitter object in a class so I wrote this code:

const char myToken[]="424832639-n2OyUiB0zvuavBz9HctBUYG2123230qnVYDgisii";
...

class myClass
{
private:
Twitter twitter(myToken);
...
}

but the arduino compiler tell me “myToken is not a type”. This is twitter constructor:
Twitter(const char *user_and_passwd);
Do you have any idea on how to call it? why I get this error? The same code in C (not C++ and so without class) works.

Do you have any idea on how to call it?

Yes. And, if you post some real code, I'll tell you. Depends on your real code, though.

first thank you very much!
this is the code:

nodo.h

#ifndef nodo_h
#define nodo_h

#include <SD.h>
#include <XBee.h>
#include <Twitter.h>

const int MAX_N_SENS=20;
const int N_ORE_ALLARME=1;
const char myToken[]="424832639-n2OyUiB0zvuavBz9HctBUYG2123230qnVYDgisii";

class nodo
{
private:
	
	String nomeStruttura;
	//di xbee
	XBee xbee;
	XBeeResponse response;
	// create reusable response objects for responses we expect to handle 
	ZBRxResponse rx;
	ModemStatusResponse msr;
	Twitter twitter(myToken);

	
public:
	
	
	
	nodo();							//costruttore
	~nodo();

};

so I only need to initialize a twitter object so that I can use it in the node.cpp

One solution is to make the twitter object global, similar to SD or RTC libraries.

You can't instance the Twitter object in the header file, with arguments, because doing so needs to execute code, and you can't do that in a class header file. You can only have executable code in a class implementation file.

There's no reason why the twit that designed that class needed to make the constructor require an argument. The constructor itself doesn't DO anything with the token except point to it. That could have been done with a begin/init method.

I prefer to keep object that I use only in a class as private object for that class. Too many globlal object make the code less clear and less easy to maintain

I prefer to keep object that I use only in a class as private object for that class. Too many globlal object make the code less clear and less easy to maintain

You like object oriented programming, don't you? Then you know that a constructor (the function, that is) should only initialize member variables and do nothing that can fail (like opening files, setting up devices etc). A better place to instantiate the twitter object would be a function init().

You can do it however what you have/had is wrong.

class A{
 public:

  Twitter twitter(myToken);
};

In this instance, 'twitter' is a function returning a type 'Twitter' with one parameter of type 'myToken', that is why you get an undeclared type error.

class A{
 public:

  A( void ) : twitter( myToken ) { return; }

  Twitter twitter;
};

This declares a data member 'twitter' of type 'Twitter' and it gets constructed during class A's initialiser list. This all depends on what parameters 'Twitter' takes in its constructor. However if myToken is global, just use that directly, or declare the array as a static member of the class.

thanks to everyone!