This question already has answers here:
constexpr not compiling in VC2013
(4 answers)
Closed 9 years ago.
Please help me with this error.
I am trying to make a sample that explains constexpr keyword in c++. I am using Visual Studio 2013.
Following is the code of my cpp file.
#include <iostream>
#include <stdexcept>
const int sampleconstant = 5;
constexpr int constTest(void)
{
return sampleconstant;
}
int main()
{
std::cout << constTest();
getchar();
return 0;
}
This shows compile time error as follows:
Error 1 error C2144: syntax error : 'int' should be preceded by ';'
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I may be doing something silly here. But really can't figure out this error. Code looks ok to me. If any one can help me with error please help.
As already told you, it is not supported on VS.
You can see at this link a list of featured supported by the compilers: http://wiki.apache.org/stdcxx/C++0xCompilerSupport
Related
This question already has answers here:
Weird compiler error: Cannot convert parameter from 'int' to 'int &&'
(4 answers)
Closed 9 years ago.
Today I wanted to try to bring my project from visual c++ 2010 to visual c++ 2013.
I get this error in visual c++ 2013 which I did not get when compiling with 2010 version.
//somewhere in the SimpleObject_list class
std::unordered_map<std::string, SimpleObject *> Object_list;
//method which is giving me the error
void SimpleObject_list::Add(const char *Object_name, SimpleObject * Object_pointer){
cout << "SimpleObject listed as: " << Object_name << endl;
Object_list.insert(std::make_pair<std::string,SimpleObject *>(Object_name, Object_pointer));
}
the error is:
error C2664: 'std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,SimpleObject *> std::make_pair<std::string,SimpleObject*>(_Ty1 &&,_Ty2 &&)' : cannot convert argument 2 from 'SimpleObject *' to 'SimpleObject *&&'
what am I doing wrong? Why I did not get any error in vc++ 2010?
Thanks
Change
Object_list.insert(std::make_pair<std::string,SimpleObject *>(Object_name, Object_pointer));
to
Object_list.insert(std::make_pair(Object_name, Object_pointer));
This question already has answers here:
Why am I getting "error: expected '}'" in C++ but not in C?
(3 answers)
Closed 9 years ago.
I have the following code in a header file:
enum {false,true};
and I have my main function in main.c. if I change the extention to main.cpp
I get the following error:
Error C2059: syntax error 'constant'
Im using visual c++, any Idea why`?
true and false are keywords representing constant values in C++. You cannot use them to name things such as enum values.
As an example, the following would compile
enum { false_, true_ };
int main() {}
false and true are reserve words in C++. You can't redefine it as variable.
So, playing around with constexpr, MSVC (Visual Studio 2012) gave me an error while trying to qualify my function with the constexpr keyword using this simple program (includes omitted):
constexpr int factorial(int n)
{
return n <= 1 ? 1 : (n * factorial(n-1));
}
int main(void)
{
const int fact_three = factorial(3);
std::cout << fact_three << std::endl;
return 0;
}
constexpr was underlined red with the following message:
Error : this declaration has no storage class or type specifier
and trying to compile the program gave the following output:
1>main.cpp(5): error C2144: syntax error : 'int' should be preceded by ';'
1>main.cpp(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
It really puzzles me as it is the very example that Cppreference uses to illustrate the use of constexpr. At first I used a simple function that returned a literal, i.e. constexpr int func(){return 5;}, but which yielded the same error. I interpreted the first message as "it should be a member function of a struct or class", but the example from Cppreference shows that it's not necessary apparently.
So, what am I obviously missing here ?
Quite simply - because Visual Studio doesn't support constexpr (prior to Visual Studio 2015).
Note that MSVC++11 is Visual Studio 2012; VC++10 is Visual Studio 2010.
I use Visual Studio 2005
When I compile, I get this error:
Error 1 error C2146: syntax error : missing ';' before identifier 'mDropEndTime'
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
struct MB_SYN_DROPITEM_UPDATE : MSGBUF
{
long mCid; // Index
unsigned long mItemIdx; // idx
TIMESTAMP_STRUCT mDropEndTime; // This is error line
};
Why doesn't C++ know TIMESTAMP_STRUCT?
TIMESTAMP_STRUCT is something defined in sqlext.h
You must add
#include <sqlext.h>
Because TIMESTAMP_STRUCT is not part of the C++ standard.
I need to refactor a .dll for a Zinc based Flash application.
After copy&paste a class from the master to the branch, I'm getting some strange compiling errors:
GameInfo.h(15): error C2146: syntax error : missing ';' before identifier 'm_wsVersion'
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
GameInfo.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
The addressed code:
// removed the comments
#include "stdafx.h"
#include <string.h>
class GameInfo {
public:
UINT m_uiGameId;
wstring m_wsVersion; // Line 15
UINT m_uiCheckSum;
wstring m_wsFilePath; // Same error report as on line 15
public:
static BOOL createFromFile(wstring path, GameInfo &target); // error "error C2061: syntax error : identifier 'wstring'" thrown
};
I use Visual Studio 2010 and in the IDE itself everything is okay, no syntactical errors or something like that. And as said I did not touch the code, headers seem fine.
Has anyone a clue what about this error?
Try using the string header, and qualifying the namespace:
#include <string>
class GameInfo {
....
std::wstring m_wsVersion;
};
#include <string> is the right standard include in C++ for string classes and use std::wstring.
I strongly recommend AGAINST using a using namespace std; inside one of your headers, as you would force anybody using the header to pull in the std stuff into the global namespace.