Why this simple code is giving syntax error? - c++

#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.

Related

Visual C++ unit testing errors when including required code

I'm new to C++, I have a Visual C++ project in Visual Studio 2008 (stuck with it I'm afraid) and I'm trying to get unit tests to work. I've got my code and I've got my new test project set up but any time I include the header file of the code I want to test, I get 138 compilation errors.
#include "stdafx.h"
//#include "../ProjName/ProjName.h"
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace TestProjName
{
...various code created by the wizard...
[TestMethod]
void Test1()
{
Assert::AreEqual(0,1);
};
};
My code compiles (and runs) fine until the #include to my ProjName is uncommented. When it is uncommented, I get a lot of errors from the VS libraries along the lines of:
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\vadefs.h(89) : error C4956: 'va_list *' : this type is not verifiable
,
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h(2027) : error C4956: 'threadlocaleinfostruct *' : this type is not verifiable
and
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wchar.h(235) : error C2337: 'SA_Post' : attribute not found
Has anyone come across this before? Might anyone suggest a (probably simple) thing I'm overlooking?
Found my own solution after a good while googling. My test project used /clr:safe common language runtime support. Switching it to /clr fixed the issue for me.

Errors building Freetype application with Visual Studio

I've been going bonkers the last week on this problem.
Microsoft Visual Studio Community 2013
Freetype 2.5.5
Windows 8.1
Building as C++ application
I've been trying to build against a static library for Freetype, I've tried after building the lib using the included VC2010 project and also downloading a pre-built library with no luck. I always get the same errors below. I've tried with multiple examples and the same. I'm able to successfully compile and link against the lib using gcc (after building a .a library), this problem seems to be isolated to Visual Studio..
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2143: syntax error : missing '}' before '('
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2143: syntax error : missing ';' before '<L_TYPE_raw>'
1>f:\audio\libs\header\freetype\fterrdef.h(35): error C2059: syntax error : '<L_TYPE_raw>'
1>f:\audio\libs\header\freetype\fterrors.h(164): error C2143: syntax error : missing ';' before '}'
1>f:\audio\libs\header\freetype\fterrors.h(177): error C2059: syntax error : '}'
1>f:\audio\libs\header\freetype\fterrors.h(177): error C2143: syntax error : missing ';' before '}'
1>f:\audio\libs\header\freetype\freetype.h(38): error C2143: syntax error : missing ';' before '{'
1>f:\audio\libs\header\freetype\freetype.h(38): error C2447: '{' : missing function header (old-style formal list?)
Example code that can cause this error:
#include <windows.h>
#include <ft2build.h>
#include FT_FREETYPE_H
int main(int argc, char **argv)
{
return 0;
}
I had the same issue while building FreeType2 in VS2013 with VS2013 toolset (SDK). No Google results seem to have answer to this so far so I thought I'd share even though the thread is bit old (but the problem is still recent! FreeType ver. 2.6 still suffers from the same problem).
For reference, this can be reproduced by minimal example:
#include <ft2build.h>
#include FT_FREETYPE_H
FT_Library library;
So the problem and solution is quite simple but was unfortunately buried in output log and wasn't that obvious at first glimpse so it needed some investigation.
There is a clash with header names between FreeType2 library and Windows SDK, namely with the fttypes.h file which gets dragged in from:
C:\Program Files (x86)\Windows Kits\8.1\Include\shared\fttypes.h
Instead, VS should include FT2 header that is located in:
your_FT2_root\include\fttypes.h
This is easy to workaround - in your Project Properties (Alt+F7) rearrange header search paths so FreeType2 path is first (for me bringing FT2 at the top worked like a charm).
Hope this helps!
Cheers,
Henryk

VS 2012 template errors

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.

Newbie chrome-plugin developer needs help getting started with NPAPI

Although only having done a very little in C++ before I'm trying to compile the following chrome plugin so that I can see how it works and use that as a starting point to develop something similar: http://code.google.com/p/minimizetotray/source/browse/trunk/?r=17#trunk%2FDLL
So far I have taken the following steps: downloaded the source, opened it in MS Visual Studio Pro 2008, and obtained a few of SDKs and headerfiles it was asking for including the latest version of the NPAPI headers: http://npapi-sdk.googlecode.com/svn/trunk/headers/
Now I get the following errors when I try to compile and have no idea how to sort this.
Compiling...
JSMethods.cpp
c:\documents and settings\dell customer\desktop\dll\jsmethods.cpp(92) : error C2039: 'UTF8length' : is not a member of '_NPString'
c:\program files\microsoft visual studio 9.0\vc\include\plugin\npruntime.h(85) : see declaration of '_NPString'
c:\documents and settings\dell customer\desktop\dll\jsmethods.cpp(101) : error C2039: 'UTF8characters' : is not a member of '_NPString'
c:\program files\microsoft visual studio 9.0\vc\include\plugin\npruntime.h(85) : see declaration of '_NPString'
Etc...
Apart from those two errors it all seems dandy, its not asking for missing includes or anything. Any help appreciated!
Unless I'm mistaken on the latest SDK the _NPString struct is defined as...
typedef char NPUTF8;
typedef struct _NPString {
const NPUTF8 *UTF8Characters;
uint32_t UTF8Length;
} NPString;
And in your code you are calling UTF8length instead of UTF8Length (uppercase L).

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.