Unkown type name error

Why i got this error? what’s problem ?

Particle p; <<<<<<------ Unknown type name ‘Particle’

    #pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);
    Particle p;
    ofFbo fbo;
    float history;
    float time0;
};

class Params {
public:
    void setup();
    ofPoint eCenter;
    float eRad;
    float velRad;
    float lifeTime;
    float rotate;
};

extern Params param; // Decleration

You need to define the Particle class before it is used, otherwise the compiler wont kknow what a Particle is.

#include "ofMain.h"
#include "Particle.h" // Include its definition here ...

class ofApp : public ofBaseApp{
///...

So like that?

#pragma once

#include "ofMain.h"
#include "Particle.h"

class ofApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);
    Particle p;
    ofFbo fbo;
    float history;
    float time0;
};

class Params {
public:
    void setup();
    ofPoint eCenter;
    float eRad;
    float velRad;
    float lifeTime;
    float rotate;
};

extern Params param; // Decleration

I have define class in my ofApp.cpp

class Particle {
public:
    Particle();
    void setup();
    void update( float dt );
    void draw();
    ofPoint pos;
    ofPoint vel;
    float time;
    float lifeTime;
    bool live;
    
};

If you don’t have the Particle class in another file (like Particle.h) then it needs to go before the ofApp declaration.


#pragma once

#include "ofMain.h"

class Particle {
public:
    Particle();
    void setup();
    void update( float dt );
    void draw();
    ofPoint pos;
    ofPoint vel;
    float time;
    float lifeTime;
    bool live;

};

class ofApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);
    Particle p;
    ofFbo fbo;
    float history;
    float time0;
};

class Params {
public:
    void setup();
    ofPoint eCenter;
    float eRad;
    float velRad;
    float lifeTime;
    float rotate;
};

extern Params param; // Decleration

And then the implementation would also go in the ofApp.cpp file.

I tried but get more errors.

this is my ofApp.h

#pragma once

#include "ofMain.h"

class Particle {
public:
    Particle();
    void setup();
    void update( float dt );
    void draw();
    ofPoint pos;
    ofPoint vel;
    float time;
    float lifeTime;
    bool live;
    
};

class ofApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);
    Particle p;
    ofFbo fbo;
    float history;
    float time0;
};

class Params {
public:
    void setup();
    ofPoint eCenter;
    float eRad;
    float velRad;
    float lifeTime;
    float rotate;
};

extern Params param; // Decleration

And this is my ofApp.cpp

#include "ofApp.h"

class Particle {
public:
    Particle();
    void setup();
    void update( float dt );
    void draw();
    ofPoint pos;
    ofPoint vel;
    float time;
    float lifeTime;
    bool live;
    
};


Params param;        //Definition of global variable
void Params::setup() {
    eCenter = ofPoint( ofGetWidth() / 2, ofGetHeight() / 2 );
    eRad = 50;
    velRad = 200;
    lifeTime = 1.0;
    rotate = 90;
}

Particle::Particle() {
    live = false;
}


ofPoint randomPointInCircle( float maxRad ){
    ofPoint pnt;
    float rad = ofRandom( 0, maxRad );
    float angle = ofRandom( 0, M_TWO_PI );
    pnt.x = cos( angle ) * rad;
    pnt.y = sin( angle ) * rad;
    return pnt; }


void Particle::setup() {
    pos = param.eCenter + randomPointInCircle( param.eRad );
    vel = randomPointInCircle( param.velRad );
    time = 0;
    lifeTime = param.lifeTime;
    live = true;
}

void Particle::update( float dt ){
    if ( live ) {
        //Rotate vel
        vel.rotate( 0, 0, param.rotate * dt );
        //Update pos
        pos += vel * dt;    //Euler method
        //Update time and check if particle should die
        time += dt;
        if ( time >= lifeTime ) {
            live = false;   //Particle is now considered as died
        }
    } }



void Particle::draw(){
    if ( live ) {
        //Compute size
        float size = ofMap(
                           fabs(time - lifeTime/2), 0, lifeTime/2, 3, 1 );
        //Compute color
        ofColor color = ofColor::red;
        float hue = ofMap( time, 0, lifeTime, 128, 255 );
        color.setHue( hue );
        ofSetColor( color );
        ofCircle( pos, size );  //Draw particle
    }
}





//--------------------------------------------------------------
void ofApp::setup(){
    ofSetFrameRate( 60 );    //Set screen frame rate
    //Allocate drawing buffer
    int w = ofGetWidth();
    int h = ofGetHeight();
    fbo.allocate( w, h, GL_RGB32F_ARB );
    //Fill buffer with white color
    fbo.begin();
    ofBackground(255, 255, 255);
    fbo.end();
    //Set up parameters
    param.setup();          //Global parameters
    history = 0.995;
    time0 = ofGetElapsedTimef();
}

//--------------------------------------------------------------
void ofApp::update(){
    
    //Compute dt
    float time = ofGetElapsedTimef();
    float dt = ofClamp( time - time0, 0, 0.1 );
    time0 = time;
    //If the particle is not active - activate it
    if ( !p.live ) {
        p.setup(); }
    //Update the particle
    p.update( dt );
   
}

//--------------------------------------------------------------
void ofApp::draw(){
    ofBackground( 255, 255, 255 );  //Set white background
    //1. Drawing to buffer
    fbo.begin();
    //Draw semi-transparent white rectangle
    //to slightly clearing a buffer (depends on history value)
    ofEnableAlphaBlending();         //Enable transparency
    float alpha = (1-history) * 255;
    ofSetColor( 255, 255, 255, alpha );
    ofFill();
    ofRect( 0, 0, ofGetWidth(), ofGetHeight() );
    ofDisableAlphaBlending();
    //Draw the particle
    ofFill();
    p.draw();
    fbo.end();
    //2. Draw buffer on the screen
    ofSetColor( 255, 255, 255 );
    fbo.draw( 0, 0 );
    
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    
}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
    
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
    
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){ 

}

You are defining the Particle class in both the header and the implementation.

You need to remove it from the implementation (cpp file).

yes i deleted this part from cpp file

class Particle {
public:
    Particle();
    void setup();
    void update( float dt );
    void draw();
    ofPoint pos;
    ofPoint vel;
    float time;
    float lifeTime;
    bool live;

};

then i get this errors