scope of instantiated class / was not declared in this scope
<p>I'm a new person to C++, but i have learned a little Java and I/m working with SDL for the first time at the same time but my problem is I'm trying to create an object (paddle) p1 and p2. </p>

<p>this</p>

<pre><code>#ifndef PONG_H_
#define PONG_H_
#undef main
#include &lt;SDL/SDL.h&gt;
#include &lt;SDL/SDL_image.h&gt;
#include &lt;SDL/SDL_ttf.h&gt;



class paddle{
private:
    int y;
    int yv;
    int x;
public:

    paddle(){
    y = 0;
    yv = 0;
    x = 0;
    }

    paddle(int ex, int why, int vel){
        y = why;
        yv = vel;
        x = ex;
        }

    void setY(int ycoord) {y = ycoord;}
    void setV(int velocity){ yv = velocity;}
    void setX(int xcoord) {x = xcoord;}
    int getX() {return x;}
    int getY() {return y;}
    int update(){y += yv; return y;}




};


class Pong { //pong class where everythin gets its name and a purpose.

private:

    SDL_Surface * Paddle;
    SDL_Surface * Ball; //SDL_Surface pointer for Ball
    SDL_Surface * screen;   //SDL_Surface  pointer to backbuffer

public:
    int Running;
    Pong(); //eh..

    int OnExecute(); //another function returning a value.
    int w; //width of screen
    int h; //height of screen
    bool OnInit();
    void OnEvent(SDL_Event* Event);
    void OnLoop();
    void OnRender();
    void OnCleanup();


    void redraw( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Make a temporary rectangle to hold the offsets
    SDL_Rect offset; //Give the offsets to the rectangle
    offset.x = x; offset.y = y;
    SDL_BlitSurface( source, NULL, destination, &amp;offset );//Blit the surface
    offset.x =0; offset.y=0; //resets the offsets sicne they apaprently dont reset per use.
    };

};


#endif /* PONG_H_ */
</code></pre>

<p>is my header file, it contains the main functions of pong class also but I omitted those to make things less convoluted. Let me know if those are needed for a good answer.</p>

<p>and i declare the objects here...</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;SDL/SDL.h&gt;

#include "Pong.h"
paddle p1;
paddle p2;

Pong::Pong(){
h = 768;
w = 1024;
screen = NULL;
Paddle = NULL;
Ball = NULL;

Running = true;
atexit(SDL_Quit);

}

int Pong::OnExecute() {
    if(OnInit() == false)
        return-1;
    SDL_Event Event;
    while(Running) {
        while(SDL_PollEvent(&amp;Event)) {
            OnEvent(&amp;Event);
        }

        OnLoop();
        OnRender();
    }
    OnCleanup();
return 0;
}

int main( int argc, char* args[]) {
    Pong theApp;
    return theApp.OnExecute();
}
</code></pre>

<p>but what sort of makes it difficult is i use it in...here:</p>

<pre><code>#include "Pong.h"
void Pong::OnEvent(SDL_Event* Event) {
    if(Event-&gt;type == SDL_QUIT)
        Running = false;
    switch(Event-&gt;type)
    {

        case SDL_KEYDOWN: //look for key holds
            switch(Event-&gt;key.keysym.sym) //check key values and changes coords respectiely
            {
            default:
                break;
            case SDLK_UP:
                p2.setV(-2);
                break;

            case SDLK_DOWN:
                p2.setV(2);
                break;

            case SDLK_w:
                p1.setV(-2);
                break;

            case SDLK_s:
                p1.setV(2);
                break;

            case SDLK_ESCAPE:
            Running = false;
                break;
            }
            break;
        case SDL_KEYUP:
            switch(Event-&gt;key.keysym.sym)
            {
            default:
                break;
                case SDLK_UP:
                    p2.setV(0);
                    break;

                case SDLK_DOWN:
                    p2.setV(0);
                    break;

                case SDLK_w:
                    p1.setV(0);
                    break;

                case SDLK_s:
                    p1.setV(0);
                    break;
            }
            break;
        break;//break of Key holding event check
    }
}
</code></pre>

<p>Its hard for me to ask the question because I don't know where to begin. I tried many different weird things and I'm just lost now. If you need any more info I'll be happy to provide.</p>

<pre><code>void Pong::OnLoop(){

    if(p1.getY()&lt;=0){
        p1.setV(0);
        p1.setY(0);
    }
    if(p2.getY()&lt;=0){
        p2.setV(0);
        p2.setY(0);
    }
    if(p1.getY()&gt;=h - Paddle-&gt;h){
        p1.setV(0);
            p1.setY(h - Paddle-&gt;h);
        }
    if(p2.getY()&gt;=h - Paddle-&gt;h){
        p2.setV(0);
            p2.setY(h - Paddle-&gt;h);
        }
}
</code></pre>

<p>..\src\Pong_OnLoop.cpp:11:5: error: 'p1' was not declared in this scope  </p>

<p>..\src\Pong_OnLoop.cpp:15:5: error: 'p2' was not declared in this scope  </p>

<p>..\src\Pong_OnLoop.cpp:19:5: error: 'p1' was not declared in this scope  </p>

<p>..\src\Pong_OnLoop.cpp:23:5: error: 'p2' was not declared in this scope  </p>
