CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: unusual error

  1. #1
    Join Date
    Feb 2005
    Location
    Croatia
    Posts
    192

    unusual compiler error

    first of all sorry for such general title, i dont know how to describe this problem

    in my code i have a "define" and my document pointer
    Code:
    //defaults.h
    ...
    #define SOME_NUMBER 20
    ...
    
    //MyView.h line 10
    ...
    CAppDoc* GetDocument() const;
    ...
    when i change the value of SOME_NUMBER to, lets say, 21 the program wont compile and visual studio throws this errors

    ...MyView.h(10): error C2143: syntax error : missing ';' before '*'
    ...MyView.h(10): error C2501: 'MyView::CAppDoc' : missing storage-class or type specifiers
    ...MyView.h(10): error C2501: 'MyView::GetDocument' : missing storage-class or type specifiers
    ...MyView.h(10): warning C4183: 'GetDocument': missing return type; assumed to be a member function returning 'int'

    BUT, when i comment line 10 , rebuild everything (with errors, naturally), and then uncomment and rebuild again it all works fine, no error, no warnings, no bugs in program

    is this normal MS VS issue?
    Last edited by l00p1n6; November 28th, 2005 at 02:07 PM. Reason: added "compiler" to the title

  2. #2
    Join Date
    Aug 2001
    Location
    Texas
    Posts
    645

    Re: unusual error

    First, change the title of the thread to mean something. You put "Unusual
    error." Error in what.

    Something like "Error when compiling"

    Can you attach a small project that has the same problem?

    You may be getting mixed with the Precompiled Headers. Show the Cpp file
    that you are compiling with these headers.

  3. #3
    Join Date
    Feb 2005
    Location
    Croatia
    Posts
    192

    Re: unusual error

    all my .h files have #ifndef _CLASS_NAME_ #define _CLASS_NAME_ and #endif _CLASS_NAME_ (where _CLASS_NAME_ is unique for each class) so i think that i dont get mixed with precompiled headers

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: unusual error

    Sorry, but my impression is that you want to play with us "guess what's in my code".
    Anyhow, once "rebuild all" saves you, then rebuild all and "game over".
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Feb 2005
    Location
    Croatia
    Posts
    192

    Re: unusual error

    Quote Originally Posted by ovidiucucu
    Sorry, but my impression is that you want to play with us "guess what's in my code".
    Anyhow, once "rebuild all" saves you, then rebuild all and "game over".
    please mr., do not insult me so much:(

    i have posted numerus problems in codeguru forums and almost all have been answered (those that werent, just showed me that im on the wrong track)
    i would NEVER take time from fellow programers who voluntarely in their own spare time help programming beginners just to amuse myself

    problem i'm facing is for my project, wich has a lot of code by now. that is the one reason i am not posting it. the other reason is my mentors "orders" (i dont know a better word): not to post my whole code for other people to solve my problems

    thanks to all you guys (you too ovidiucucu), my project is at late beta phase. i have my brother testing it and am implementing some user friendly add-ons (tool-tips, nicer buttons, multiple screen resoulution support etc.)

    i will post my whole project in code guru page (if they agree) after it gets accepted by my mentor so that all users can see my mistakes (it has more than 10 working versions)

    now, about my problem... since i have just small changes to make(default itmem positions in formwiev) i will continue the way i do now:
    1. change defined value,
    2. rebuild,
    3. comment the problematic line - 10 (actualy it is 57)
    4. rebuild,
    5. uncomment the problematic line
    6. rebuild
    7. look at dialog layout when program is running and repeat steps 1-7 if needed

    regards
    kresimir
    Last edited by l00p1n6; November 28th, 2005 at 03:46 PM. Reason: misspelled ovidiucucu, sorry

  6. #6
    Join Date
    Aug 2001
    Location
    Texas
    Posts
    645

    Re: unusual error

    Are you working on mulitple computers?

    Maybe time difference between the different computers.

    Other than that, I'm thinking.....

  7. #7
    Join Date
    Feb 2005
    Location
    Croatia
    Posts
    192

    Re: unusual error

    phew, i think i did it

    i tried compiling my code on my friend's computer and his computer did not support the workaround i used (coment, build, uncomment, build), so i concluded it is not totaly MS VS compiler error

    then i decided to compare all files in project with the ones in previous version, and didnt found anything (maybe because my eyes were tired), next thing i tried was comparing all files in MS word, (copy-paste and save each source file in separate .doc file and then do comparison), but since i did quite a bit of cleaning since previous versions it was all messy and i gave up
    next thing i did was searching the internet for "folder comparer" and i ran into veri usefull VS plugin on codeproject's pages "Web Report 2.1"... to cut the story the plugin showed new entry in newest version of the program (thank God i did the versioning thing) it was the line:
    #include "MyView"
    in CAppDoc.h file

    i dont know how it came there or why (maybe because i use ctrl+c and ctrl+v too often
    when i commented that line and run the compilation i was thrilled, i changed my "defaults.h" entries a bit and compiled again..... perfectly, without errors

    with my problem solved im still puzzled: why did my comment-build, uncomment-build work?

    btw my file "MyView.h" does contain
    Code:
    #ifndef _MY_VIEW_
    #define _MY_VIEW_
    ...
    //code
    ...
    #endif //_MY_VIEW_
    so i dont understand what was wrong

    although my problem is solved, i would like your comments on the issue, please

    thank you
    kresimir

  8. #8
    Join Date
    Oct 2005
    Posts
    526

    Re: unusual error

    you can simply solve this problem as I always do.

    include your document class at your MyView.h file.
    it will probably looks like this :
    #include "AppDoc.h"

    CAppDoc* GetDocument();

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: unusual error

    Quote Originally Posted by l00p1n6
    although my problem is solved, i would like your comments on the issue, please
    How can anyone comment when we didn't see your code?

    All we can say is that you made a mistake.

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    Sep 1999
    Location
    malaysia
    Posts
    191

    Re: unusual error

    Hi,

    Check if you did this

    #define SOME_NUMBER 21 ; //<- the semi-colon can cause this error I think

    Good Luck
    ______________________________
    To err is human, it's the computer that causes blunders !!!

    DO: Dazzle me with your intelligence
    DON'T : Confuse me with your bullshit

  11. #11
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Re: unusual error

    Quote Originally Posted by Mustafa
    Hi,

    Check if you did this

    #define SOME_NUMBER 21 ; //<- the semi-colon can cause this error I think

    Good Luck
    do this
    add doc header file then add the view header file
    for e.g
    Code:
    #include "SampleDosc.h"
    #include "SampleView.h"
    now compile ur pgm it won't give error.
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  12. #12
    Join Date
    Feb 2005
    Location
    Croatia
    Posts
    192

    Re: unusual error

    Quote Originally Posted by Paul McKenzie
    How can anyone comment when we didn't see your code?
    All we can say is that you made a mistake.
    by the "issue" i mean how is it posible that
    1. you build a program and get errors
    2. you comment one line of code (add "//" in the beginning of a line)
    3. you build a program and get errors
    4. you uncomment the same line of code (delete "//" in step 2.)
    5. you build a program and get NO errors

    please note "NO" in step 5.

    and yes you are right (again), i did made a mistake

    Quote Originally Posted by suchuhui80
    include your document class at your MyView.h file.
    i do have that "include" in every view

    Quote Originally Posted by Mustafa
    Check if you did this
    #define SOME_NUMBER 21 ; //<- the semi-colon can cause this error I think
    no i dont have that ";" at the end of #define directive

    Quote Originally Posted by Gunaamirthavelu
    add doc header file then add the view header file
    do you mean that it has to be done by that order?
    because i almost always include .h file of appropriate class in .cpp file after "#include stdafx.h" (i dont want to mess with that 'cause VS puts it in every .cpp file by default)

    the problem was in :
    #include "MyView.h
    in MyDocument.h
    and it was solved (deleted that line), but the question still stays in place (i think)
    why did comment-uncomment evade the error?

  13. #13
    Join Date
    Feb 2002
    Posts
    4,640

    Re: unusual error

    Who knows why your workaround worked. For some reason, the compiler thought the file that actually contained the error didn't need compiling the second time around.

    Do a google search for "merge programs" or "diff programs". Personally I use a program called "WinMerge" to diff my files. Also, if you're using MSVC 6.0, there should be a program called "Windiff" that allows you to compare two files, side by side, highlighting the differences.

    Viggy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured