[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Unexplained compilation error.
From: |
Robert Heller |
Subject: |
Re: Unexplained compilation error. |
Date: |
Fri, 15 Mar 2013 12:31:32 -0500 |
Nevermind. I needed to use an additional (nested) namespace...
At Fri, 15 Mar 2013 10:41:04 -0500 Robert Heller <heller@deepsoft.com> wrote:
>
> I have stared at this code fragment and I am not seeing the error. This
> is from a piece of code that used to compile, but I am migragrating the
> code from the depreciated hash_map to an unordered_map. There is
> *obviously* something wrong here, but I am just not seeing it.
>
> ================Begin test.cc===========================
> #include <string.h>
> #include <iostream>
>
>
> #ifdef __GNUC__
> # if __GNUC__ > 3
> // GCC > 3
> # include <tr1/unordered_map>
> # define USE_UNORDERED_MAP
> # else
> // GCC < 4
> # define USE_HASH_MAP
> # include <ext/hash_map>
> # endif
> #else // ... there are other compilers, right?
> # define USE_HASH_MAP
> #endif
>
> #ifdef USE_HASH_MAP
> /** @brief Equality structure.
> *
> * Used with the hash map used for Print Options
> *
> * @author Robert Heller \<heller\@deepsoft.com\>
> *
> */
> struct eqstr
> {
> bool operator()(const char* s1, const char* s2) const
> {
> return strcmp(s1, s2) == 0;
> }
> };
> #endif
> /** @brief Option hash map, used for Print options.
> *
> * @author Robert Heller \<heller\@deepsoft.com\>
> *
> */
>
> #ifdef USE_HASH_MAP
> typedef __gnu_cxx::hash_map<const char*, string, __gnu_cxx::hash<const
> char*>, eqstr> OptionHashMap;
> #else
> typedef std::unordered_map<const char*, string> OptionHashMap;
> #endif
>
> int main(int argc, char *argv[]) {
> OptionHashMap theMap;
>
> std::cout << "GCC Major Version is " << __GNUC__ << std::endl;
> if (__GNUC__ > 3) {
> std::cout << "GCC Major Version is greater than 3" << std::endl;
> } else {
> std::cout << "GCC Major Version is less than or equal to 3" <<
> std::endl;
> }
>
> #ifdef USE_UNORDERED_MAP
> std::cout << "Using unordered_map" << std::endl;
> #endif
> #ifdef USE_HASH_MAP
> std::cout << "Using hash_map" << std::endl;
> #endif
>
> }
> ====================End test.cc==============
>
> sauron.deepsoft.com% g++ -Wall test.cc -o test
> test.cc:44: error: expected initializer before â<â token
> test.cc: In function âint main(int, char**)â:
> test.cc:48: error: âOptionHashMapâ was not declared in this scope
> test.cc:48: error: expected `;' before âtheMapâ
> sauron.deepsoft.com% g++ -v
> Using built-in specs.
> Target: x86_64-redhat-linux
> Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
> --infodir=/usr/share/info --enable-shared --enable-threads=posix
> --enable-checking=release --with-system-zlib --enable-__cxa_atexit
> --disable-libunwind-exceptions --enable-libgcj-multifile
> --enable-languages=c,c++,objc,obj-c++,java,fortran,ada
> --enable-java-awt=gtk --disable-dssi --disable-plugin
> --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
> --with-cpu=generic --host=x86_64-redhat-linux
> Thread model: posix
> gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)
>
>
--
Robert Heller -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments