VS 2012 template errors - c++

I've been using this code to marshal strings in C++/CLI for a while now. Recently I've updated to VS 2012 RC to try it out. I really liked the simple design, but none of my projects containing clix.h could be compiled. It worked great in 2010... What could be the problem? Thank you for your answers!
Here is compiler output:
Warning C4346:
'clix::detail::IsManagedString::Result'dependent name is
not a type.
Error C2988: unrecognizable template declaration/definition
Error C2059: syntax error : '<'
Error C2039: 'Result' : is not a member of '`global namespace''
Error C2143: syntax error : missing ';' before '}'
The code block errors are in:
typename detail::Select<detail::IsManagedString<SourceType>::Result>::Type<
typename detail::StringTypeSelecter<encoding>::Type,
System::String ^>::Result marshalString(SourceType string) {
// Pass on the call to our nifty template routines
return detail::StringMarshaler<
detail::IsManagedString<SourceType>::Result ? detail::CxxFromNet : detail::NetFromCxx
>::marshal<encoding, SourceType>(string);
}
An example, source file:
#include "clix.h"
int main()
{
}
Clix header file can be found on this link.

You could have just posted the issue on my blog, it's not abandoned or anything :)
I happen to have Visual Studio 2012 RC installed and fixed the issue. You can find a new version of the clix header at the location you linked.
Background: it appears Microsofts new compiler is a bit picky regarding typedefs in nested templates whose parent templates are specialized on integer types. In any case, I found a method that works in both Visual C++ 2010 and Visual C++ 2012 RC.

Related

Adding boost header files gives compile time errors

When i add the header file
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
It gives couple of errors
error C2988: unrecognizable template declaration/definition
error C2143: syntax error: missing ';' before '<'
error C2913: explicit specialization; 'boost::type_of::id2type_impl' is not a specialization of a class template
error C2059: syntax error: '<'
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
which point towards the line number 125 in typeof_impl.hpp file.
It's unclear what file you mean:
custom/boost_1_72_0/boost/typeof/typeof_impl.hpp
custom/boost_1_72_0/boost/typeof/msvc/typeof_impl.hpp
custom/boost_1_72_0/boost/typeof/dmc/typeof_impl.hpp
If you mean msvc/typeof_impl.hpp then most likely you have a preprocessor issue (where the source is mutated due to a redefined preprocessor token).
If there's no such file than #drescherjm's comment may be on point: there might be specific MSVC support missing in that version you're using.
After reading drescherjm , sehe's comments i changed some settings in the visual studio and when i changed platform Toolset from visual studio 2017 v(141) to visual studio 2015 v(140) , the program compiled sucessfully.

C2061: syntax error : identifier 'L' in qtypetraits.h

This has now cost me quite some time, so in case anybody else has this problem, here it is:
I have a C++ project using Visual Studio 2013, and with the CPP Rest SDK. Now we start using Qt (version 5.6), so I added Qt objects to the code.
I kept getting this error message:
C:\Qt\Qt5.6.0\5.6\msvc2013_64\include\QtCore/qtypetraits.h(523): warning C4003: not enough actual parameters for macro 'U'
C:\Qt\Qt5.6.0\5.6\msvc2013_64\include\QtCore/qtypetraits.h(523): warning C4003: not enough actual parameters for macro '_XPLATSTR'
C:\Qt\Qt5.6.0\5.6\msvc2013_64\include\QtCore/qtypetraits.h(523): error C2061: syntax error : identifier 'L'
C:\Qt\Qt5.6.0\5.6\msvc2013_64\include\QtCore/qtypetraits.h(527) : see reference to class template instantiation 'QtPrivate::is_default_constructible<T>' being compiled
It's not Qt's fault. It's the CPP Rest SDK. It defines a macro U, which is happily replaced for a U template parameter in qtypetraits.h.
When I define _TURN_OFF_PLATFORM_STRING in the C++ preprocessor definitions, the error disappears.

Why this simple code is giving syntax error?

#include <iostream>
using namespace std;
void fun(int i)
{
cout<<"Called with int "<<i;
}
void main()
{
using df = decltype(&fun);
}
I am getting following syntax errors in Visual Studio,
Error 1 error C2143: syntax error : missing ';' before '=' c:\users\kpranit\documents\visual studio 2012\projects\sample\sample\sample.cpp 12
Error 2 error C2873: 'df' : symbol cannot be used in a using-declaration c:\users\kpranit\documents\visual studio 2012\projects\sample\sample\sample.cpp 12
Visual Studio 2012 which, based on your project directory, is the one you're using, does not support type aliasing.
It's a C++11 feature and does not make an appearance in the MSDN documentation, even for VS2013, though I think that may just be a doc error on their part - the Microsoft site for C++11 compatibility (look for "alias templates") lists it as being available under VS2013.
So, if you want to use that feature, you'll probably have to upgrade to the later compiler.

Why is this simple template class breaking in VS 2013 and not VS 2010

Background
I recently began using VS 2013 with C# and decided to use it when I went to implement a simple heap with C++. I started framing out the heap class using a template parameter and started running into compilation errors... I have been writing templated code in VS2010 for a while and never ran into this problem until I tried compiling in VS2013.
The following code compiles and runs fine in Visual Studio 2010. It does not compile in Visual Studio 2013 and shows the following errors:
1> Heap.inl 1>c:\users\knight\desktop\heap\heap\heap.inl(13): error C2143: syntax error : missing ';' before '<'
1>c:\users\knight\desktop\heap\heap\heap.inl(13): error C2988: unrecognizable template declaration/definition
1>c:\users\knight\desktop\heap\heap\heap.inl(13): error C2059: syntax error : '<'
1>c:\users\knight\desktop\heap\heap\heap.inl(13): error C2039: 'Heap' : is not a member of '`global namespace''
1>c:\users\knight\desktop\heap\heap\heap.inl(19): error C2588: '::~Heap' : illegal global destructor
1>c:\users\knight\desktop\heap\heap\heap.inl(19): fatal error C1903: unable to recover from previous error(s); stopping compilation
Here is the Code:
Heap.hpp
#ifndef HEAP_HPP
#define HEAP_HPP
namespace Knight
{
template<class T>
class Heap
{
private:
public:
//Default Constructor
Heap();
//Default destructor
~Heap();
//Heapify
//Add Element
//Swim Element up
};
}
#include "Heap.inl"
#endif // Heap_HPP
Heap.inl
namespace Knight
{
//NAME constructor
template<typename T>
Heap<T>::Heap()
{
}
//NAME destructor
template<typename T>
Heap<T>::~Heap()
{
}
}
What I tried to do
I looked at the microsoft site looking or breaking changes and did not see any that would pertain to what I am doing here. I am using the "separate definition and implementation" trick here and I am assuming something related to this broke.
I was hoping someone could help me out and tell me what changed from 2010-2013 that is causing this compilation issue.
I noticed the file type in VS was cpp/source. It should be "Document" Changed it to Document and it still did not compile. So I removed the file from the project and re-added it and it works fine now. I believe I renamed the file to a .inl from a .cpp and VS2013 does not handle that too well. Problem solved once it is re-added and does not confuse it at CPP source.

Compiliation errors on boost files

I'm getting a lot of errors compiling code using the boost libraries, mainly when I'm using Spirit namespace. The errors are syntax errors on boost files like:
boost/spirit/home/classic/dynamic/lazy.hpp(33) : error C2143: syntax error : missing ';' before '<'
or
boost/spirit/home/classic/dynamic/lazy.hpp(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
or
boost/spirit/home/classic/utility/grammar_def.hpp(104)
: error C2039: 'nil_t' : is not a
member of 'boost::phoenix'
I am migrating from Visual Studio 6 to Visual Studio 2008 Express and from one of the oldest versions of boost to the lastest.
I'd like to know what's the problem. I'm thinking the problem can't be in the boost library.
My guess, like Timi Geusch, is an errant #define.
I've never used VS, but if there is an option to see the code after it has been passed through the preprocessor, you might be able to figure out what causing the problem.
The problem was resolved just including phoenix1 the old version of phoenix.