bcc32 compiling error (really strange!!)

This is a discussion on bcc32 compiling error (really strange!!) within the C++ Programming forums, part of the General Programming Boards category; Hello, for a while I'm facing a strange compiling error with bcc32. ..I have the following code in one of ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    26

    bcc32 compiling error (really strange!!)

    Hello,
    for a while I'm facing a strange compiling error with bcc32.

    ..I have the following code in one of the methods:

    InterfaceQT *something;

    The include for the class "InterfaceQT" is there. there's no type error, everything is just right (or should).

    Now the strange thing:

    One of the headers is the <iostream>.

    If I compile with it. I get the error:

    Error E2108 src\FindForm.cpp 184: Improper use of typedef 'InterfaceQT' in funct
    ion Find:nSearchb()
    Error E2188 src\FindForm.cpp 184: Expression syntax in function Find:nSearchb(
    )
    Error E2188 src\FindForm.cpp 187: Expression syntax in function Find:nSearchb(
    )


    Look at that first one!!! typedef!!!!!!!!!!!! IncludeQT is a class!!!!!!!

    AND if I compile WITHOUT <iostream>.....guess!!
    everything compile just fine!!

    is the second time I see this strange behavior...I'm not sure if the iostream was involved...the first time I changed lots of things, until it work...but I don't remember what I did (and I don't want to...was too mutch work)

    Please, I apreciate any help!! I really need to get this application working for my boss.

    Thanks
    #pwd
    Brazil

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    what are you including before iostream.h?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    Lots of things.....lots of QT includes, some classes I wrote....
    but from the standard C++, iostream is the only one, I guess..

    I guess I tried to change the iostream location in the source....put it above all includes...then, in the bottom right before the using std::bad_alloc (is the only thing I want from iostream)
    #pwd
    Brazil

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    so did including it above the other headers change the error?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    nope!! The error desappears when I comment
    #include <iostream>....
    #pwd
    Brazil

  6. #6
    Unregistered
    Guest
    do you use inclusion gaurds in your user defined header files?

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    gaurds???
    what is that??

  8. #8
    Unregistered
    Guest
    If you have a user defined header file like this:

    //myFile.h
    #include <iostream.h>
    void display();

    and associated cpp file like this:

    //myFile.cpp
    #include "myFile.h"
    cout << "hello";

    and you then create a program like this:

    #include <iostream.h>
    #include "myFile.h"

    int main()
    {
    display();
    return 0;
    }

    then you have a problem because you have two copies of iostream.h in the program and the compiler doesn't know which copy to use. Therefore, it frequently throws an error. If you comment out the #include <iostream.h> line then you only have the copy of iostream.h in the myFile.h file and everything will be fine.

    Since it is difficult to keep track of duplicate copies you can use an inclusion guard. An inclusion guard is a preprocessor directive that says if you find duplicate copies, only use the first copy and neglect the others. To use an inclusion guard you would do something like this (you should confirm the syntax to be sure I used it correctly)

    //myFile.h
    #ifnotdef MYFILE_H
    #define MYFILE_H
    //everything for myFile.h goes here
    #endif

    The three lines with the # signs above constitute an inclusion guard. If you use them in this fashion and then do the following in your program:

    #include <iostream.h>
    #include "myFile.h"

    everything will be okay (at least in terms of duplicate file enclosures).

  9. #9
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Do what the previous post said but use ifndef instead of ifnotdef(doesn't exist)

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    26

    Humm

    Humm....But I think the msg error is diferent in this case.
    Is something like "Bla bla bla duplicated".

    Well....all my headers have the #ifndef HEADER_H #def HEADER_H....I used to think that I could define the same standard header many times (like iostream, that I need in every cpp to handle memory errors). Anyway...I tried and...the error still there....the same "typedef"
    #pwd
    Brazil

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    Oh, and....that's what I did in all the files using iostream:

    #ifndef IOSTREAM_H
    #include <iostream.h>
    #define IOSTREAM_H
    #endif

    the error still there
    #pwd
    Brazil

  12. #12
    Unregistered
    Guest
    I suspect your last post was a typo having the include iostream.h line between the ifndef and define line. If it's not a typo, then it's a source of error. Don't put the inclusion guards around each #include <iostream.h> in every header file you write, just use the one inclusion gaurd per file, as far as I know anyway.

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    26
    Got really strange...I wrote and tested it.....then, put it back the way it was...without those #ifndef

    Anyway, what should I do?
    All my headers have inclusion guards and all my sources need <iostream>. I tested my app writing in every source:

    #ifndef IOSTREAM_H
    #define IOSTREAM_H
    #include <iostream.h>
    #endif

    And the error still there.

    Now I created an header.h with the common includes I need to avoid multiple includes of the same header.
    and tested it again.....same error
    the file was something like

    #ifndef HEADER_H
    #define HEADER_H

    #include <string>
    #include <iostream>
    #include <io>...........

    #endif

    and every cpp that needs those includes:
    #include "header.h"

    the error still there!!
    I belive I'm missing something in the class Interface (wich is the one mentioned in the error)
    Now, I tried to use it as static....before was like this:

    186: Interface *interface = new Interface;
    187:
    188: interface->load( foo );

    The error:
    Error E2108 src\FindForm.cpp 186: Improper use of typedef 'Interface' in functio
    n Find:nSearchb()

    and the test ( load declared as static now )

    Interface::load( foo );

    and....everything compiled just fine......


    I'm really lost....
    #pwd
    Brazil

  14. #14
    Unregistered
    Guest
    post the name for the h file for class known as Interface, the h file for the class known as Interface, whether the h file for the class known as Interface is located in the same directory as the compiler you are using or somewhere else, the list of included files in your program, and the couple lines immediately preceding and after the line of code flagged by your compiler.

  15. #15
    Registered User
    Join Date
    Dec 2001
    Posts
    26

    Thanks

    After some tests here, I guess the error was solved....I renamed the class Interface to interator.....maybe <iostream.h> uses that name or something,.....anyway....if I don't post anything in the forum in the next days, thats couse It's everything ok, but I don't know...since the error wasn't really "solved"...I just think it is!!!!
    Thanks a lot guys!!!
    #pwd
    Brazil

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very strange compiling bug
    By 39ster in forum C++ Programming
    Replies: 3
    Last Post: 07-15-2008, 03:16 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 11:21 AM
  4. Strange compiling problem
    By SnS CEO in forum C++ Programming
    Replies: 8
    Last Post: 08-07-2005, 05:30 PM
  5. strange result of after compiling a program
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2002, 10:54 AM

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