Could anyone help me find out what is wrong with in-class initialization of
static constexpr member varaible like in the code below ?
Using Visual Studio 2013
struct hg {
public:
static constexpr float asd = 9.0f;
};
int main() {
return 0;
}
The above code gives the following errors :
Error 1
error C2144: syntax error : 'float' should be preceded by ';'
Error 2
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Related
I am trying to make a linkedList but when I create a Head in a separate ADT with class Node Included in it it produces an error error C2143: syntax error : missing ';' before '*'
This is code for ADT of Node
#include <iostream>
#include "LinkedList.h"
using namespace std;
class Node
{
friend LinkedList;
protected:
int data;
Node *next;
public:
Node(int d =-999, Node *n = NULL);
//Mutators
void setData(int d);
void setNext(Node *n);
//Accessors
int getData ();
Node *getNext();
};
This is code for ADT LinkedList
class LinkedList
{
private:
Node *head; //This line is causing that particular error
public:
//some lines of code
};
I am completely lost tried every possible solution but can't figure out what's actually going wrong here.
#pragma comment(lib, "libmcrypt.lib")
When the platform is Visual Studio 2012 (v110), it is OK. But, when platform is WindowsApplicationForDrivers8.0, it reports error LNK2019
When I include OpenSSL in my project, I'm getting the same error.
From the MSDN.
The following sample generates LNK2019:
// LNK2019.cpp
// LNK2019 expected
extern char B[100]; // B is not in avilable to the linker
int main() {
B[0] = ' ';
}
LNK2019 can also occur when you declare but do not define a static data member. The following sample generates LNK2019:
// LNK2019b.cpp
// LNK2019 expected
struct C {
static int s;
};
// Uncomment the following line to resolve.
// int C::s;
int main() {
C c;
C::s = 1;
}
Please go to the MSDN link for full explanation
http://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx
My question is: why does VC emit warning 4365 for only one of the commented lines below, and not the other?
#pragma warning(1: 4365)
void test1(const unsigned short) {}
unsigned short test2() { return 0; }
int main()
{
const unsigned short a = 0;
const unsigned short b = 0;
test1(a + b); // This line gives no warning
test1(test2() + b); // This line gives C4365
return 0;
}
Tested under VS2010 and VS2012 Express.
For reference, the full warning text is this:
warning C4365: 'argument' : conversion from 'int' to 'const unsigned short', signed/unsigned mismatch
Using Clang 3.3 (through Clang-Win32 and ClangVSx), no warnings are reported in this code (except of course the unknown pragma).
I compiled Greta against VES2008, it reports
error C2332: 'class' : missing tag name
error C3306: 'regex::detail::<unnamed-tag>': unnamed class template is not allowed
error C2143: syntax error : missing ';' before '__builtin_alignof'
error C2059: syntax error : '__builtin_alignof'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)
relevant source code snippet:
template< typename T >
class alignof
{
struct helper
{
helper();
char m_c;
T m_t;
};
public:
enum { value = sizeof(helper)-sizeof(T) < sizeof(T) ? sizeof(helper)-sizeof(T) : sizeof(T) };
};
after precompiled, it
template< typename T >
class __alignof
{
struct helper
{
helper();
char m_c;
T m_t;
};
public:
enum { value = sizeof(helper)-sizeof(T) < sizeof(T) ? sizeof(helper)-sizeof(T) : sizeof(T) };
};
I have not found answers after googling. what caused this and how to resolve it?
Although alignof does not seem to be a reserved word in VS2008, it's so similar to _alignof that it may be confusing the issue.
Try changing the name of your class to something different.
why would the following sniplet
#include <atlcom.h>
...
class FormRegionWrapper;
...
// Errorsource :
typedef IDispEventSimpleImpl
<2, FormRegionWrapper, &__uuidof(FormRegionEvents)>
FormRegionEventSink;
will give me the following errors:
// Error ouput:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
?!?
(The sniplet is taken from here : Building a C++ Add-in for Outlook 2010 ). My environment : MS Visual Studio 2012 Professinal, and Windows 7-64.
PS 1: Here what the help says about the IDispEventSimpleImpl :
// Help IDispEventSimpleImpl Class : This class provides implementations of
// the IDispatch methods, without getting type information from a type library.
// template <
// UINT nID,
// class T,
// const IID* pdiid
// >
// class ATL_NO_VTABLE IDispEventSimpleImpl :
// public _IDispEventLocator<nID, pdiid>
//
// Requirements
// -------------------
// Header: atlcom.h
Have you included atlcom.h so that the template IDispEventSimpleImpl is defined? Are the declarations of other classes (I assume written by you) used in the template declaration available? And i don't think that forward definition of FormRegionWrapper is enough, can you try and include the declaration of that class, so that template sees it?
UPDATE
Not sure if this will help much, but I replaced the source of FormRegionWrapper.h with the colde below (example from the MSDN page on IDispEventSimpleImpl:
#pragma once
#include "stdafx.h"
#include <vector>
#include <algorithm>
_ATL_FUNC_INFO Event1Info1 = { CC_CDECL, VT_EMPTY, 1, { VT_I4 } };
class CEventHandler;
typedef IDispEventSimpleImpl <1234, CEventHandler, &__uuidof(IDispatch)>
DummySink;
class CEventHandler : public DummySink
{
public:
BEGIN_SINK_MAP(CEventHandler)
SINK_ENTRY_INFO(1234, __uuidof(IDispatch), 1, OnEvent1, &Event1Info1)
END_SINK_MAP()
void __stdcall OnEvent1(LONG l)
{
//ATLASSERT(l == 445533);
if (l != 445533)
OutputDebugString(L"l is not 445533\n");
}
HRESULT Advise1234(IUnknown * punk) {
return IDispEventSimpleImpl<1234, CEventHandler, &__uuidof(IDispatch)>::DispEventAdvise(punk);
}
};
If this works, you can safely assume that the template is being included correctly.
Add this line after the #include directives in FormRegionWrapper.h:
using namespace ATL;