Author Topic: Noob problem : Linking new class  (Read 3785 times)

interstar

  • Guest
Noob problem : Linking new class
« on: November 01, 2010, 09:11:04 pm »
Hi, I just started with CodeBlocks to work with openFrameworks.

Working on Ubuntu (Karmic Koala).

I can compile and run the example openFrameworks programs OK. However, when I try to create a new class (using File menu, New Class) CodeBlocks creates the new files like this :

It puts the new class X.cpp file in the "src" directory (along with the other files of the openFrameworks project).
It puts the X.h file in an "include" directory.

However, in the Projects window of CodeBlocks, the X.cpp file is shown under Sources/src (as opposed to the src branch where the rest of the files are) and the header file is put under Headers/include and it can't be seen at all.

If I move the .h file into the src directory then try to compile I get another error. Here is the complete code :

X.h
Code
#ifndef X_H
#define X_H
#include <iostream>

class X {
    public:
        static float f;
        int i;

        X();
        virtual ~X();
    protected:
    private:
};

#endif // X_H


X.cpp
Code
#include "X.h"

using namespace std;

X::X() {
    f = 0.1;
    i = 2;
    cout << "Created";
}

X::~X() {
    //dtor
}

testApp.cpp (the main openFrameworks app)

Code
#include "testApp.h"
#include "X.h"


//--------------------------------------------------------------
void testApp::setup(){
    X x = new X();
}

...

And here's the error message :

In member function ‘virtual void testApp::setup()’:
error: ‘X’ was not declared in this scope
error: expected ‘;’ before ‘x’

Any ideas what's going wrong here? It looks like X isn't visible inside testApp.cpp even though there's an #include "X.h" just above and no compiler message about not finding it. Remember, all files are now in the same directory.