Showing posts with label Compile Error. Show all posts
Showing posts with label Compile Error. Show all posts

Sunday, January 04, 2009

Compiler issue: Nested template specialization in GCC

(Jan 4, 2009)

I tried to declare a vector that has another container in it. For example,
vector<vector<int>> vecInt;

This syntax works within MS Visual C++, but not in GCC. In GCC, the compiler says
`>>' should be `> >' within a nested template

The above error message is clear. We just need to insert space between angle brackets to fix the issue and change the above statement to
vector< vector<int> > vectInt;

However,
if the inner container is more complicated, the compiler error message
may make you wonder what is happening. For example, if the inner
container is Boost's dynamic bitset:
vector<boost::dynamic_bitset<>> vecBsRoiData;

The error message will be
vecBsRoiData' was not declared in this scope
The
error message is very confusing, but can be handled in the same way by
inserting space between angle brackets and change it to
vector< boost::dynamic_bitset<> > vecBsRoiData;

Note: in reality, we only need to insert space to the closing bracket, but doing so may make the code looks strange. Therefore, I inserted space to both opening and closing brackets.

Friday, September 21, 2007

Precompiled header does not exist

Friday Sep 21, 2007

I wasted about 20 minutes to figure out how to solve this compile error: precompiled header does not exist. I performed rebuild the entire solution with the hope that the precompiled header will be recreated.

Finally, I found that we could explicitly tell Visual Studio to create a precompiled header as shown in the figure below. After a successful compilation, Visual Studio will automatically change the 'Create' option to 'Use' option instead.

Monday, April 16, 2007

valarray problem in Visual Studio

(Apr 16, 2007)

I tried to use valarray in Visual Studio and got some compile errors and warnings:
"warning C4003: not enough actual parameters for macro 'min'
warning C4003: not enough actual parameters for macro 'max'

error C2059: syntax error : ')'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\valarray(427) : see reference to class template instantiation 'std::valarray<_ty>' being compiled

error C2334: unexpected token(s) preceding ':'; skipping apparent function body
...
"

These problem will occur only when we try to use statically linked MFC library. In http://www.codeguru.com/forum/archive/index.php/t-342787.html, Paul suggested that we need to make sure that valarray is included before afx stuff. This is because MS implements min and max macro and defines them in afx pre-compile header file. Any class that has min and max will have this problem.

However, if I switch the order, it seems that all declaration of valarray will be removed and I just got other compiler errors. It seems that the solution from Paul could not work for my situation.

After trying for a while, I finally decided to rename valarray.h to valarray_mod.h and change the function names from min and max to minimum and maximum instead.