Thread: MSVC9 Error?

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    MSVC9 Error?

    Hey guys.

    I attempted to compile what I have done so far and recived two bizzare messages from the compiler refering to files with the software. The program seems to compile ok without any syntax errors. I really do not know how to get rid of these errors, please help!

    main:
    Code:
    #include "heartrates.h"
    #include <iostream>
    
    // main function - begin program execution
    //
    int main ( void )
    {
    	HeartRates hr( "", "", 0, 0, 0 );
    
    	std::cin.get(); // prevent console closing in debug state
    }
    heartrate.h
    Code:
    #ifndef HEARTRATES_H
    #define HEARTRATES_H
    
    #include <string>
    
    class HeartRates
    {
    public:
    	HeartRates ( std::string, std::string, int, int, int );
    
    	void setFirstName ( std::string );
    	void setLastName ( std::string );
    	void setDay ( int );
    	void setMonth ( int );
    	void setYear ( int );
    
    	std::string getFirstName() const;
    	std::string getLastName() const;
    	int getDay() const;
    	int getMonth() const;
    	int getYear() const;
    
    	int getAge() const;
    	int getMaximumHeartRate() const;
    	int getTargetHeartRate() const;
    
    private:
    	std::string firstName,
    		lastName;
    	int day,
    	     month,
    	     year;
    };
    
    #endif // heartrates.h
    heartrates.cpp ( unfinished )
    Code:
    #include "heartrates.h"
    #include <iostream>
    
    // constructor - ensure data member begin in a legal state
    HeartRates::HeartRates ( std::string first, std::string last, 
    		         int dy, int mth, int yr )
    {
    }
    The errors:

    Code:
    c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) : error C2144: syntax error : '__w64 unsigned int' should be preceded by ';'
    c:\program files\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    Double Helix STL

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I just pasted this code into a project on GCC and it produced no such errors...FWIW...so either the error was caused by something not posted here or there is something unique about MSVC9....
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I don't have that compiler, so I tried plugging it into Dinkumware. It compiled just fine, but that was in one source file and with MSVC 8 and earlier.

    I would suspect that you've inadvertently used a name which is a macro or something. Maybe "day", or "year", or "dy"; just try changing all your variable names around, see if that makes a difference.

    Failing that, I'd guess your compiler to be broken. There doesn't seem to be anything wrong there that I can see.

    ---

    Incidentally, why does MSVC 7 (and g++) accept and compile this code?
    Code:
    #include <string>
    #include <iostream>
    
    class HeartRates
    {
    public:
    	HeartRates ( std::string, std::string, int, int, int ) {}
    
    	void setFirstName ( std::string );
    	void setLastName ( std::string );
    	void setDay ( int );
    	void setMonth ( int );
    	void setYear ( int );
    
    	std::string getFirstName() const;
    	std::string getLastName() const;
    	int getDay() const;
    	int getMonth() const;
    	int getYear() const;
    
    	int getAge() const;
    	int getMaximumHeartRate() const;
    	int getTargetHeartRate() const;
    
    private:
    	std::string firstName,
    		lastName;
    	int day,
    	     month,
    	     year;
    };
    
    // main function - begin program execution
    //
    int main ( void )
    {
    	HeartRates hr( "", "", 0, 0, 0 );
    
    	std::cin.get(); // prevent console closing in debug state
    }
    Shouldn't it give you linker errors because of the undefined functions? Or does that only matter if you use them . . . ? That's quite strange, I would have predicted linker errors.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by dwks View Post
    Incidentally, why does MSVC 7 (and g++) accept and compile this code?
    There's no linker error, because there is no unresolved symbols. Since you are not calling any of the functions, there is no attempt to look up any of the function names, therefore there is nothing for the linker to complain about.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by dwks View Post
    Shouldn't it give you linker errors because of the undefined functions? Or does that only matter if you use them . . . ? That's quite strange, I would have predicted linker errors.
    If the functions aren't called, then they don't have to exist. For instance, you implement a non-copyable class like this:

    Code:
    class noncopyable
    {
    private:
        noncopyable( const noncopyable & ); // private, no implementation
        noncopyable &operator=( const noncopyable & ); // private, no implementation
    };
    The only time you MUST implement a function that isn't called anywhere is if it's virtual, since the vtable contains a reference to it.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Interesting. I knew that worked for template classes, but I wasn't aware it worked for ordinary ones too. I guess I'd never tried it before. But of course it does make sense.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I think what's more odd is that MSVC and g++ will compile and run this:
    Code:
    #include <iostream>
    
    class Test
    {
    public:
        void foo()
        {   
            std::cout << "Hello World\n";
        }   
    };
    
    int main()
    {
        Test* t = NULL;
        t->foo();
    }
    It makes sense once you look into what's happening, but intuitively, you would think it would crash
    bit∙hub [bit-huhb] n. A source and destination for information.

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Microsoft's own code is filled with junk like this:

    Code:
    ERR SomeClass::Foo()
    {
        if( this == NULL )
            // somebody called through a NULL pointer
            return SOME_ERROR;
        ...
        return OK;
    }
    Guuuuuuh.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, I see what you mean. It's just passing a this pointer which is never dereferenced, but the "t->foo()" syntax makes it look like you are in fact dereferencing it. Tricky.

    [edit] Checking explicitly for NULL inside the function seems like a bit of a waste to me, especially if it's left in production code. And anyway, that's one of the easiest ways for me to catch some errors: get a segfault, fire up the debugger, and notice this is 0x0 . . . . [/edit]

    The only time you MUST implement a function that isn't called anywhere is if it's virtual, since the vtable contains a reference to it.
    Right. I've definitely had this happen to me before.
    Last edited by dwks; 12-30-2009 at 01:52 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM