Altera_Forum
Honored Contributor
19 years agoClass and C++
Hi everyone,
I'm brand new developer with NiosII and C++, and I'm experiencing some problems with NiosII IDE, expecially in building application in C++. I created a classe called "thread". I wrote 2 files, an simple header file thread.h and a cpp file, thread.cpp. During building, I receive this error message: Compiling thread.cpp... ../thread.cpp:10: error: new types may not be defined in a return type ../thread.cpp:10: error: return type specification for constructor invalid ../thread.cpp: In member function `void thread::begin()': ../thread.cpp:16: error: `TIMER_BASE' undeclared (first use this function) ../thread.cpp:16: error: (Each undeclared identifier is reported only once for each function it appears in.) ../thread.cpp:16: error: expected primary-expression before ')' token ../thread.cpp: In member function `void thread::end()': ../thread.cpp:26: error: `TIMER_BASE' undeclared (first use this function) make: *** [obj/thread.o] Error 1code listed below: thread.h # ifndef _THREAD_H_# define _THREAD_H_ # define TIMEOUT# define TIME# include "altera_avalon_timer_regs.h" class thread { public: int state; int ticks; thread(); ~thread(); void begin(); void end(); int getState(); } # endif //_THREAD_H_
code listed below: thread.cpp # include <system.h> # include "thread.h"# include "altera_avalon_timer_regs.h" void thread::thread() {} void thread::~thread() {} void thread::begin(void) { // inizializzazione timer e partenza IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_BASE, TIME); IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_BASE, 0x00); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BASE, 0x07); state = 1; ticks = 0; } void thread::end(void) { // terminazione timer IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BASE, 0x0b); state = 0; } int thread::getState(void) { return state; } So, I don't understand where are the problems: 1. What does it mean "new types may not be defined in a return type"? 2. Why TIMER_BASE is unknown, although is defined in <system.h> header file? Someone can help me? Thanks. G.