Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Class and C++

Altera_Forum
Honored Contributor II
1,152 Views

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 1 

 

code 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&#39;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.
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
440 Views

 

--- Quote Start ---  

originally posted by g.sanzi@Mar 28 2006, 10:03 AM 

hi everyone, 

 

i&#39;m brand new developer with niosii and c++, and i&#39;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()&#39;: 

../thread.cpp:16: error: `timer_base&#39; 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 &#39;)&#39; token 

../thread.cpp: in member function `void thread::end()&#39;: 

../thread.cpp:26: error: `timer_base&#39; undeclared (first use this function) 

make: *** [obj/thread.o] error 1 

 

Code listed below: thread.h[/b] 

# 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&#39;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. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13853) 

--- Quote End ---  

[/b] 

--- Quote End ---  

 

 

i solved myself: it&#39;s only for a fucked ";" after class declaration!!!!!!!
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

hello, 

I cannot define a class using Nios II IDE environment! the class is defined in basicOCR.h as follow: 

 

--- Quote Start ---  

class basicOCR{ 

public: 

float classify(IplImage* img,int showResult); 

basicOCR (); 

void test();  

private: 

char file_path[255]; 

int train_samples; 

int classes; 

CvMat* trainData; 

CvMat* trainClasses; 

int size; 

static const int K=10; 

CvKNearest *knn; 

void getData(); 

void train(); 

}; 

--- Quote End ---  

 

Although "Support C++" is activated, errors occur: 

 

--- Quote Start ---  

../basicOCR.h: At top level: 

../basicOCR.h:25: error: syntax error before "basicOCR" 

../basicOCR.h:25: error: syntax error before '{' token 

../basicOCR.h:30: error: syntax error before ':' token 

 

--- Quote End ---  

 

any ideas ? thanks
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

Is your .h file included from a .c file or a .cpp? I think it needs to be .cpp so that Eclipse compiles it in C++ mode.

0 Kudos
Altera_Forum
Honored Contributor II
440 Views

Actually it did (basicOCR.cpp)

0 Kudos
Altera_Forum
Honored Contributor II
440 Views

Hmmm I don't think that you need to rename the header files to .hpp to make the compiler stay in C++ mode. 

The include statement isn't inside an extern "C" {} block by any chance?
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

renaming the header files came out with nothing! 

the basicOCR.cpp includes the header file as (#include "basicOCR.hpp"), but does this have to do with the header file itself? 

I'm sorry if I couldn't get your last reply!
0 Kudos
Altera_Forum
Honored Contributor II
440 Views

Be sure the class declaration in the header file ends with a ;, like: 

 

class abc { //..... }; Bill
0 Kudos
Reply