typedef class and class

This is a discussion on typedef class and class within the C++ Programming forums, part of the General Programming Boards category; I started using Dev-C++ again, and in this program I'm working on I have some classes. I defined them as ...

  1. #1
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552

    typedef class and class

    I started using Dev-C++ again, and in this program I'm working on I have some classes. I defined them as usual, class and then classname, open brace, code, close brace, semicolon. When I try to make an instance of my class, it keeps saying that my classes are used as a type, but not defined as a type and so on. The only way I have found to get around it is to use the old-style
    Code:
    typedef TagClassName { }ClassName;
    I have a struct as well, and it doesn't give me these errors when I make an instance of it. What's up?

    edit: I could also just put class before the name of my class when I make an instance of it. I still don't get this. Is this the way you are supposed to do it? I know in MSVC++ I could get by without doing this, and Dev-C++ now uses GCC 3.2, which is supposed to be a lot stricter than it used to be.
    Last edited by frenchfry164; 11-29-2003 at 03:05 PM.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Not sure what you mean...
    Code:
    typedef class _A
    {
    
    
    } A;
    
    class _B
    {
    
    
    };
    
    int main()
    {
    A a;
    _B b;
    
    }
    This works fine for me...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Paste a minimalistic program that compiles and has the least amount of dependencies that illustrates your problem. I have never had this issue with gcc or dev-c++ (which uses gcc). You should be able to demonstrate your problem in 1 file and a paragraph of code.

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Okay, this is weird. I made a new project and it worked the way where you just do
    Code:
    class classname{ };
    It won't accept it in just that one project! This is strange.

    edit: I just figured it out. It's an overload problem. There's something else defined that has the name Polygon in OpenGL's header (or something OGL's header includes). I think it's something from GDI or something. I gotta pick a new name now . Man, I wish people would use naming conventions that prevent this from happening.
    Last edited by frenchfry164; 11-29-2003 at 05:43 PM.

  5. #5
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    So put your class in a namespace...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > Man, I wish people would use naming conventions that prevent this from happening.
    Which is exactly the problem namespaces were invented to solve.
    So now is the time to figure out how to use them properly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class
    By Elysia in forum C++ Programming
    Replies: 18
    Last Post: 10-20-2008, 08:45 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Replies: 8
    Last Post: 10-02-2005, 12:27 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

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