program:
CCompussGradientOperator dlg;
string p = "preqitt";
string k = "Kirnch";
string r3 = "Robison";
f(dlg.DoModal() == IDOK)
{
CDib dib = m_Dib;
BOOL ret = FALSE;
if(dlg.m_Combo_Operators == p )
{
switch(dlg.m_nFunction)
{
case 0: ret ;
}
}
}
error:
Error 18 error C2065: 'string' : undeclared identifier d:\2nd\imagetool\imagetooldoc.cpp 870 1 ImageTool
string is a data type then why it does make me error.. its strange for me...
any one can help me ..thanks
Have you included <string> header ? Also it is in namespace std.
Change string to std::string. Also, do you have #include <string> at the top of the source file?
Related
i have code. but I can not understand why he swears?
This is line 17
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
**Parse error: syntax error, unexpected '=', expecting ')' in /home/s2332/***.com/www/admin/controller/shipping/novaposhta.php on line 17**
if (!empty($this->request->post['refresh']) && !empty($this->request->post['novaposhta_key'])) {
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $city_result;
} elseif (!empty($address_result = $this->model_module_novapochta->getAdress($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $address_result;
}
};
Your if statement is wrong...
You have write:
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
must be:
$city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']);
if (!empty($city_result)) {
//your code here
I have this function. I created it with libxml2 and std::string library.
#ifndef KNIHOVNA_H
#define KNIHOVNA_H
#include <string>
#include <libxml/tree.h>
std::string hledaniString(int index,xmlDocPtr sharedString)
{
std::string Istring;
xmlAttrPtr attr;
xmlChar *attrValue;
xmlNodePtr nodeLevel1 = sharedString->children;
int maxValue;
int aIndex;
attr = xmlHasProp(nodeLevel1, (const xmlChar*)"uniqueCount");
if (attr !=NULL)
{
attrValue = xmlGetProp(nodeLevel1, (xmlChar *)"uniqueCount");
}
else return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
nodeLevel1 = nodeLevel1->children;
maxValue = atoi((const char *) attrValue);
xmlFree(attrValue);
if (maxValue<=index) return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
for (aIndex = 0;aIndex < index; aIndex++ )
{
nodeLevel1 = nodeLevel1->next;
}
nodeLevel1 = nodeLevel1->children;
attrValue = xmlNodeGetContent(nodeLevel1);
xmlFree(attrValue);
attrValue = xmlNodeGetContent(nodeLevel1);
Istring = (char *) attrValue;
xmlFree(attrValue);
return Istring;
#endif // KNIHOVNA_H
I use it in Code Block project where is everything ok and in qt creator project where I get these errors:
/usr/include/c++/4.8/string:38: In file included from /usr/include/c++/4.8/string:38:0,
/usr/include/c++/4.8/bits/stl_relops.h:-1: In function 'std::string getString(int, xmlDocPtr)':
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected '=' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected identifier before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected primary-expression before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/home/daffy/qt projektz/revize/main.cpp:15: error: expected '}' at end of input
Could someone help me please ?
I have a c++ program that I'm trying to port from VS98 to VS2003 (incremental steps). One error that occurs throughout is "Error 2275"
For instance: k:\RR\chart\chartdlg.cpp(2025): error C2475: 'CRrDoc::cFldFilter' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
The offending code is shown below:
void CDataPage::OnBtnLabelField()
{
FLDID fid ;
LPMFFIELD f ;
CRrApp *pApp = (CRrApp *)AfxGetApp();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CRrDoc *pDoc = (CRrDoc *)pFrame->GetActiveDocument();
CSelectFieldDlg dlg;
//**************************************************
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter;
//dlg.ck = CRrDoc->*zcFldFilter;
//**************************************************
dlg.ck = pDoc->cFldFilter ;
dlg.TitleTextID = IDS_2676;
fid = (FLDID)dlg.DoModal();
if (fid != NOID)
{
f = pDoc->m_pComposite->mfbyndx(fid);
// find index
int i, iCount;
iCount = m_lboxLabel.GetCount();
for (i = 0; i < iCount; i++)
{
if(fid == m_lboxLabel.GetItemData(i))
{
m_lboxLabel.SetCurSel(i);
OnSelchangeComboLabel();
}
}
}
}
I tried handling it according to a Microsoft page: But that just generated a set of other problems (the commented code between the asterisks). Note that I also commented out the following line:
dlg.ck = pDoc->cFldFilter
Unfortunately, this leads to a new error: k:\RR\chart\chartdlg.cpp(2022): error C2440: 'initializing' : cannot convert from 'BOOL (__cdecl )(LPMFFIELD)' to 'BOOL CRrDoc:: '
The definition in the .H file looks like:
public:
static BOOL cFldFilter(LPMFFIELD f);
Any ideas how to handle the pointer-to-member issue?
since you have:
static BOOL CRrDoc::cFldFilter(LPMFFIELD f);
its type is not a member variable but a function:
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter; // doesn't work
BOOL (*zcFldFilter)(LPMFFIELD) = &CRrDoc::cFldFilter; // works
Since dlg.ck is of a correct type, you should do
dlg.ck = &CRrDoc::cFldFilter;
I am having problems referencing an Enumeration from one header file to another.
I have "Unit.h" which contains:
enum CombatRating
{
CR_HASTE_MELEE = 17,
CR_HASTE_RANGED = 18,
CR_HASTE_SPELL = 19,
};
Then "Object.h" which contains:
void ApplyPercentModFloatValue(uint16 index, float val, bool apply)
{
float value = GetFloatValue(index);
ApplyPercentModFloatVar(value, val, apply);
if (apply && index == CR_HASTE_MELEE && value > 130.86f)
value = 130.86f;
SetFloatValue(index, value);
}
When I build my project, I receive "error C2065: 'CR_HASTE_MELEE' : undeclared identifier". I tried an include for "Unit.h" within "Object.h" but that gives me loads of errors too.
Is there any way to reference the Enum across header files so that a percentage can be applied to "CR_HASTE_MELEE"?
Thanks
I've got the following code:
std::for_each(tokens.begin(), tokens.end(), [&](Token& t) {
static const std::unordered_map<std::wstring, Wide::Lexer::TokenType> mapping([]() -> std::unordered_map<std::wstring, Wide::Lexer::TokenType>
{
// Maps strings to TokenType enumerated values
std::unordered_map<std::wstring, Wide::Lexer::TokenType> result;
// RESERVED WORD
result[L"namespace"] = Wide::Lexer::TokenType::Namespace;
result[L"for"] = Wide::Lexer::TokenType::For;
result[L"while"] = Wide::Lexer::TokenType::While;
result[L"do"] = Wide::Lexer::TokenType::Do;
result[L"type"] = Wide::Lexer::TokenType::Type;
// PUNCTUATION
result[L"{"] = Wide::Lexer::TokenType::OpenCurlyBracket;
result[L"}"] = Wide::Lexer::TokenType::CloseCurlyBacket;
return result;
}());
if (mapping.find(t.Codepoints) != mapping.end()) {
t.type = mapping.find(t.Codepoints)->second;
return;
}
t.type = Wide::Lexer::TokenType::Identifier; // line 121
});
This iterates through a list of tokens, and judging by the contents of the codepoints, assigns them a value from the associated enum. If it's not found, then give it a value of "Identifier". But this fails to compile.
1>Lexer.cpp(121): error C2065: '__this' : undeclared identifier
1>Lexer.cpp(121): error C2227: left of '->Identifier' must point to class/struct/union/generic type
This is the full error, no warnings, no other errors. What? How can I fix this error?
Edit: I did some significant refactoring, and I've got the exact same problem in a somewhat simpler lambda.
auto end_current_token = [&] {
if (current != Wide::Lexer::Token()) {
current.type = Wide::Lexer::TokenType::Identifier; // error line
if (reserved_words.find(current.Codepoints) != reserved_words.end())
current.type = reserved_words.find(current.Codepoints)->second;
if (punctuation.find(current.Codepoints[0]) != punctuation.end())
current.type = punctuation.find(current.Codepoints[0])->second;
tokens.push_back(current);
current = Wide::Lexer::Token();
}
};
I've cleaned and rebuilt the project.
I fixed the problem.
auto end_current_token = [&] {
if (current != Wide::Lexer::Token()) {
// WORKAROUND compiler bug- dead code
struct bug_workaround_type {
int Identifier;
};
bug_workaround_type bug;
bug_workaround_type* __this = &bug;
current.type = Wide::Lexer::TokenType::Identifier;
if (reserved_words.find(current.Codepoints) != reserved_words.end())
current.type = reserved_words.find(current.Codepoints)->second;
if (punctuation.find(current.Codepoints[0]) != punctuation.end())
current.type = punctuation.find(current.Codepoints[0])->second;
tokens.push_back(current);
current = Wide::Lexer::Token();
}
};
No, really. Now it compiles and runs just fine.
FWIW I tried to concoct a minimal working sample in order to compile on VS2010 and compiled the following without error.
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
namespace Wide { namespace Lexer {
enum TokenType
{
OpenCurlyBracket,
CloseCurlyBacket,
Namespace,
For,
While,
Do,
Type,
Identifier,
};
} }
struct Token
{
std::wstring Codepoints;
Wide::Lexer::TokenType type;
};
int main()
{
std::vector<Token> tokens;
std::for_each(tokens.begin(), tokens.end(), [&](Token& t) {
static const std::unordered_map<std::wstring, Wide::Lexer::TokenType> mapping([]() -> std::unordered_map<std::wstring, Wide::Lexer::TokenType>
{
// Maps strings to TokenType enumerated values
std::unordered_map<std::wstring, Wide::Lexer::TokenType> result;
// RESERVED WORD
result[L"namespace"] = Wide::Lexer::TokenType::Namespace;
result[L"for"] = Wide::Lexer::TokenType::For;
result[L"while"] = Wide::Lexer::TokenType::While;
result[L"do"] = Wide::Lexer::TokenType::Do;
result[L"type"] = Wide::Lexer::TokenType::Type;
// PUNCTUATION
result[L"{"] = Wide::Lexer::TokenType::OpenCurlyBracket;
result[L"}"] = Wide::Lexer::TokenType::CloseCurlyBacket;
return result;
}());
if (mapping.find(t.Codepoints) != mapping.end()) {
t.type = mapping.find(t.Codepoints)->second;
return;
}
t.type = Wide::Lexer::TokenType::Identifier; // line 121
});
}
Could you bisect the minimum edit that show the problem, starting from this code?
I've got the same problem right now. I used other types, but for your case it will be like this:
auto end_current_token = [&] {
using Wide::Lexer::TokenType; // <-- this line solves problem
if (current != Wide::Lexer::Token()) {
current.type = Wide::Lexer::TokenType::Identifier;
Now it compiles well.