Go Down

Topic: What's wrong with this c++ code? (Read 1 time) previous topic - next topic


Apr 09, 2010, 07:26 pm Last Edit: Apr 09, 2010, 07:57 pm by maxmike Reason: 1
I am converting the Xbee library to use both Serial and NewSoftSerial, so it can be used in conjunction with USB access to the mcu. But I'm not sure why I'm getting this error:

softxbee.cpp: In member function 'void softxbee::begin(long int)':
softxbee.cpp:23: error: '((softxbee*)this)->softxbee::Nss' does not have class type

Code: [Select]
#ifndef softxbee_h
#define softxbee_h

#include <WProgram.h>
#include <inttypes.h>
#include <../NewSoftSerial/NewSoftSerial.h>

class softxbee {
     softxbee(uint8_t, uint8_t);

     uint8_t _rxpin, _txpin;
     boolean _usingsoftserial;
     NewSoftSerial& Nss(uint8_t, uint8_t);
     void begin(long baud);

#endif //softxbee _h

Code: [Select]
#include "softxbee.h"
#include "WProgram.h"
#include "HardwareSerial.h"
#include <../NewSoftSerial/NewSoftSerial.h>

     _usingsoftserial = false;

softxbee::softxbee(uint8_t rxpin, uint8_t txpin){
     _usingsoftserial = true;
     _rxpin = rxpin;
     _txpin = txpin;
     Nss(rxpin, txpin);

void softxbee::begin(long baud) {
     if (!_usingsoftserial)

My sketch to test this:
Code: [Select]
#include      <softxbee.h>
#include      <NewSoftSerial.h>

softxbee xbee;                                                // coordinator

void setup()
xbee = softxbee(8,9);

void loop()


1. You don't have to re-include headers or such everywhere, just do it once in your library's header or cpp file (for WProgram.h, inttypes.h, NewSoftSerial.h, etc); when you include your header, the others will be included automatically.

2. Your problem appears to be that the compiler can't find the NewSoftSerial library; I think it may have to do with your relative link - have you tried just including "NewSoftSerial.h", without any path information (relative or otherwise)?

I recently wrote a library that I am still testing, and I included NewSoftSerial; but I don't remember how I did it exactly and it isn't in front of me - if none of the above works, and you can wait (and you don't get any other answers from others that help), I'll try to remember to post here about it again (if not, PM me).

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.


Thanks, Cr0sh - changing the include doesn't affect the problem.
I'm just trying to instantiate a NewSoftSerial object when the softxbee constructor is called.Maybe you could find a similar line in your code.
Will try some more. Found:

but his solution doesn't seem to help me here.


Writing "NewSoftSerial& Nss(uint8_t, uint8_t);" declares a new method called Nss, not an object. Just write "NewSoftSerial& Nss;" to declare an object.

To initialize it you are supposed to use an initialization list in the constructor. I've never had to do this on an Arduino yet so I don't know if it works but this is what it looks like:

Code: [Select]
softxbee::softxbee(uint8_t rxpin, uint8_t txpin)
: Nss(rxpin, txpin)  // this is an initializer
     _usingsoftserial = true;
     _rxpin = rxpin;
     _txpin = txpin;

Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html


Apr 10, 2010, 02:06 am Last Edit: Apr 10, 2010, 03:02 am by maxmike Reason: 1
Thanks to both of you! The problem was that the default constructor also needed an initialization for Nss  --> softxbee::softxbee() : Nss(2,1)
so I gave it pins 1 and 2 as a default.

My own problem is that I've been doing Java for so long that stepping back into the medieval world of C++ with all its contrived artifacts is a serious drag for me. However, I do recognize we'd need at least a 100MHz Arduino to support Java.

Go Up