namespace does not exist

This is a discussion on namespace does not exist within the C++ Programming forums, part of the General Programming Boards category; when i compile this code i get 13 errors and 2 warnings, can someone point me where i am going ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    98

    namespace does not exist

    when i compile this code i get 13 errors and 2 warnings, can someone point me where i am going wrong?
    Code:
    #include <tyfc.h>
    #include "graphics.h"
    
    
    namespace GL = GraphicsLibrary;
    
    class MyApp : public TYFCApp {
    public:
    	MyApp() : TYFCApp("Graphics", 300, 200)
    	{}
    	void Initialize();
    };
    static MyApp app;
    
    void MyApp::Initialize()
    {
    	static GL::Line<MyApp> line(app, 5, 5, 260, 160);
    	addshape(line);
    	static GL::Rectangle<MyApp> rect(app, 25, 30, 75, 100);
    	addshape(rect);
    	static GL::Circle<MyApp> circle(app, 200, 85, 60);
    	addshape(circle);
    }
    Now the errors
    Code:
    --------------------Configuration: Cpp10 - Win32 Debug--------------------
    Compiling...
    Cpp10.cpp
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(6) : error C2878: 'GraphicsLibrary' : a namespace or class of this name does not exist
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(18) : error C2653: 'GL' : is not a class or namespace name
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(18) : warning C4091: 'static ' : ignored on left of 'class Line' when no variable is declared
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(18) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(18) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(19) : error C2065: 'line' : undeclared identifier
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(20) : error C2653: 'GL' : is not a class or namespace name
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(20) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(20) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(21) : error C2065: 'rect' : undeclared identifier
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(22) : error C2653: 'GL' : is not a class or namespace name
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(22) : warning C4091: 'static ' : ignored on left of 'class Circle' when no variable is declared
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(22) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(22) : error C2143: syntax error : missing ';' before '<'
    c:\documents and settings\administrator\desktop\c++trash\cpp10.cpp(23) : error C2065: 'circle' : undeclared identifier
    Error executing cl.exe.
    
    Cpp10.obj - 13 error(s), 2 warning(s)
    I think the first error is making all the other erors happen.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    make sure you have qualified GraphicsLibrary properly. It may be nested inside another namespace maybe. Hard to tell from what you have posted. Is namespace GraphicsLibrary properly declared in graphics.h?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    98
    here is graphics .h
    Code:
    #ifndef GRAPHICS_H
    #define GRAPHICS_H
    #include <shape.h>
    
    class Line : public Shape  {
        int ex, ey;   // end point of line
    public:
        Line(int x1, int y1, int x2, int y2) : 
                    Shape(x1, y1), ex(x2), ey(y2)
        {  }
        virtual void draw();
    };
    class Rect : public Shape  {
        int height, width;
    public:
        Rect(int x, int y, int ht, int wd) :
              Shape(x, y), height(ht), width(wd)
        {  }
        virtual void draw();
    };
    class Circle : public Shape  {
        int radius;
    public:
        Circle(int x, int y, int rd) :
              Shape(x, y), radius(rd)
        {  }
        virtual void draw();
    };
    #endif
    i dont see a GraphicsLibrary in it nowhere.im learning this out of a book, im all lost now lol.and when you say it might be inside another namespace, how would i go about finding that out?

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    unnested namespace
    Code:
    namespace unnested
    {
       class empty {};
    }
    
    int main()
    {
       unnested::empty obj;
       return 0;
    }
    nested namespace
    Code:
    namespace unnested
    {
       class empty {};
    
       namespace nested
       {
          class empty {};
       }
    }
    
    int main()
    {
       unnested::empty obj;
       unnested::nested::empty obj2;
       return 0;
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    im learning this out of a book
    Make sure that the book is specific to your compiler/graphics library.

    Sorry if that's an obvious suggestion. I assume you know that there is no "standard" graphics.h

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    98
    yes i know the graphics.h is not standard.i used the graphics.h off the cd-rom that came with it but used it with visual c++ instead of Quincy 99. didnt know the compiler would make that much differance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. namespace tm?
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 01-28-2009, 02:02 PM
  2. Defining a namespace.
    By leeor_net in forum C++ Programming
    Replies: 6
    Last Post: 01-24-2009, 06:17 AM
  3. extern namespace?
    By Brafil in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2009, 07:06 AM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. using namespace error
    By johnd in forum Windows Programming
    Replies: 12
    Last Post: 08-30-2001, 07:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21