Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Class 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 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.

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- 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!!!!!!!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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

    
    class abc
    {
    //.....
    };
    
    Bill