Mike Wahler wrote:
What you posted above (once I removed the "..." lines) compiled
OK for me. Perhaps you should post the real code that gave
the errors.
Ok. This is not entirely standard code, but the Q is.
#ifndef WINCHECKER_H
#define WINCHECKER_H
/*
* Checks information on the version of Windows and provides
* access points to test SP, and HotFixes.
*/
#include <windows.h>
#include <winnt.h>
#include <vector>
#include <string>
class WinChecker
{
OSVERSIONINFO os_version_info ;
enum { WIN95, WIN98, WINME, WINNT3, WINNT4, WIN2K, WINXP, WIN2003 };
public:
WinChecker();
std::string sp_version() const;
bool check_hf(std::v ector< std::string >& hot_fixes) const;
bool check_sp(std::s tring &sp_exact_match ) const;
unsigned int version() const;
};
class WinChecker_GTNT SIX
{
OSVERSIONINFOEX os_version_info ;
enum { WINNT, WIN2K, WINXP, WIN2003 };
public:
WinChecker_GTNT SIX();
bool sp_equal_or_gre ater_than(unsig ned float sp) const;
bool check_hotfixes( std::vector< std::string >& hot_fixes) const;
unsigned int version() const;
};
#endif
The output of compiler:
$ g++ -c -I../include WinChecker.cpp
In file included from WinChecker.cpp: 1:
.../include/WinChecker.h:33 : parse error before numeric constant
.../include/WinChecker.h:33 : missing ';' before right brace
.../include/WinChecker.h:35 : parse error before `public'
.../include/WinChecker.h:38 : short, signed or unsigned invalid for `sp'
.../include/WinChecker.h:38 : non-member function `bool
sp_equal_or_gre ater_than(float )' cannot have `const' method
qualifier
.../include/WinChecker.h:39 : non-member function `bool
check_hotfixes( std::vector<std ::string, std::allocator< std::string>&)'
cannot have `const' method qualifier
.../include/WinChecker.h:40 : non-member function `unsigned int
version()' cannot
have `const' method qualifier
.../include/WinChecker.h:41 : parse error before `}' token
WinChecker.cpp: 15: syntax error before `::' token
WinChecker.cpp to be complete:
#include "WinChecker .h"
#include <stdexcept>
WinChecker::Win Checker()
{
os_version_info .dwOSVersionInf oSize = sizeof(OSVERSIO NINFO);
if (!GetVersionEx( &os_version_inf o))
{
throw std::runtime_er ror("Could not get version info of
Windows.");
}
}
WinChecker_GTNT 6::WinChecker_G TNT6()
{
os_version_info .dwOSVersionInf oSize = sizeof(OSVERSIO NINFOEX);
if (!GetVersionEx( &os_version_inf o))
{
throw std::runtime_er ror("Could not get extended version info of
Windows.");
}
}
std::string WinChecker::sp_ version() const
{
return static_cast<cha r*>(os_version_ info.szCSDVersi on);
}
bool WinChecker::che ck_sp(std::stri ng &sp_exact_match ) const
{
return sp_exact_match ==
static_cast<cha r*>(os_version_ info.szCSDVersi on);
}
Commenting out the OSVERSIONINFOEX doesn't get rid of the parse error
on #33. There is a design error in that I will be making the enums
public, but this is what fails to compile.
Compiler info:
$ g++ -v
Reading specs from c:/mingw/bin/../lib/gcc-lib/mingw32/3.2.3/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld
--with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw
--enable-threads --disable-nls --enable-languages=c++,f 77,objc
--disable-win32-registry --disable-shared --enable-sjlj-exceptions
Thread model: win32
gcc version 3.2.3 (mingw special 20030504-1)
Thanks.