I'm doing some tests to a LinkedList, that has two pointers: one point to the next item in the list and the other point to a random node within the list.
Here is the code:
struct Node
{
Node* pNext; // a pointer to the next node in the list
Node* pReference; // a pointer to a random node within the list
int number; // an integer value
};
/**
* This version works for small/medium lists, using recursion.
*/
Node* duplicateList(Node* n)
{
if (n == NULL) return NULL;
return new Node()
{
number = n->number,
pNext = duplicateList(n->pNext),
pReference = duplicateList(n->pReference)
};
}
I'm getting the following errors (VS2010):
d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(21): error C2143: syntax error : missing ';' before '{'
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(22): error C2065: 'number' : undeclared identifier
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(23): error C2065: 'pNext' : undeclared identifier
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(24): error C2065: 'pReference' : undeclared identifier
1>d:\dornad\my documents\visual studio 2010\projects\test\test.cpp(25): error C2143: syntax error : missing ';' before '}'
Thanks.
This bit is not valid C++:
return new Node()
{
number = n->number,
pNext = duplicateList(n->pNext),
pReference = duplicateList(n->pReference)
};
Change it to this:
Node* pNode = new Node();
pNode->number = n->number;
pNode->pNext = duplicateList(n->pNext);
pNode->pReference = duplicateList(n->pReference);
return pNode;
Add a constructor to Node:
struct Node
{
Node(Node* next, Node* ref, int number) : pNext(next), pReference(ref), number(number) { }
// ...
};
then
return new Node(a, b, c);
Related
I would like to run an application in qt creator. But when i click on build, it showing error in carddetect.cpp
The error occurs here: void CardDetect::aamvaIssuerList()
But I can't find out what that error is.
124: error: C2059: syntax error : '{'
124: error: C2143: syntax error : missing ';' before '{'
124: error: C2143: syntax error : missing ';' before '}'
This is my code:
#include "carddetect.h"
#include <QDebug>
void CardDetect::aamvaIssuerList(){
issuerList [ "636026" ] = (struct issuer) {"Arizona", "AZ", "L"};
issuerList [ "0636021"] = (struct issuer) { "Arkansas", "AR", "" };
issuerList [ "636014" ] = (struct issuer) { "California", "CA", "L" };
issuerList [ "636020" ] = (struct issuer) { "Colorado", "CO", "NN-NNN-NNNN" };
issuerList [ "636010" ] = (struct issuer) { "Florida", "FL", "LNNN-NNN-NN-NNN-N" };
issuerList [ "636018" ] = (struct issuer) { "Iowa", "IA", "NNNLLNNNN" };
}
and carddetect.h is
#ifndef CARDDETECT_H
#define CARDDETECT_H
#include <QMap>
#include "magcard.h"
struct issuer {
QString name;
QString abbreviation;
QString format;
};
class CardDetect {
public:
CardDetect( MagCard *_card = 0 );
void setCard( MagCard *_card );
private:
MagCard *card;
void processCard();
void luhnCheck();
void creditCardCheck();
void aamvaCardCheck( QString expDate );
void aamvaIssuerList();
QMap<QString,struct issuer> issuerList;
};
#endif // CARDDETECT_H
That code working #keltar
but now in this function
void CardDetect::aamvaCardCheck( QString expDate ) {
if( card->encoding == IATA )
return; //we're only going to support ABA for now
struct issuer issuerInfo;
QString iin = card->accountNumber.left( 6 );
issuerInfo = issuerList.value( iin );
if( issuerInfo.name.isEmpty() ) {
iin = card->accountNumber.mid( 1, 6 );
issuerInfo = issuerList.value( iin );
if( issuerInfo.name.isEmpty() )
return; // this is not a known AAMVA card, abort
}
It showing error
error: C2512: 'issuer' : no appropriate default constructor available
error: C2512: 'issuer::issuer' : no appropriate default constructor available
in struct issuer issuerInfo;
Since you cannot use compound literals, here is an example of how it could be done:
Add constructor to your structure:
struct issuer {
issuer(const char *nm, const char *abbr, const char *fmt) : name(nm),
abbreviation(abbr), format(fmt) {}
QString name;
QString abbreviation;
QString format;
};
And change your function to:
void CardDetect::aamvaIssuerList(){
issuerList [ "636026" ] = issuer("Arizona", "AZ", "L");
// same for the rest of the lines
}
There are other ways to do the same, of course.
I have an structure AVFilter,
AVFilter avfilter_vsrc_color = {
.name = "color", // error here
.description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input."),
.priv_class = &color_class,
.priv_size = sizeof(TestSourceContext),
.init = color_init,
.uninit = uninit,
.query_formats = color_query_formats,
.inputs = NULL,
.outputs = color_outputs,
.process_command = color_process_command,
};
and AVFilter is defined as,
typedef struct AVFilter {
const char *name;
const char *description;
const AVFilterPad *inputs;
const AVFilterPad *outputs;
const AVClass *priv_class;
int flags;
int (*init)(AVFilterContext *ctx);
int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
void (*uninit)(AVFilterContext *ctx);
int (*query_formats)(AVFilterContext *);
int priv_size; ///< size of private data to allocate for the filter
struct AVFilter *next;
int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
int (*init_opaque)(AVFilterContext *ctx, void *opaque);
} AVFilter;
I m getting error like ,
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(268): error C2143: syntax error : missing '}' before '.'
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(268): error C2143: syntax error : missing ';' before '.'
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(268): error C2059: syntax error : '.'
Please let us know which line is 268!
Please try removing the comma for
.process_command = color_process_command,
and try compiling it again. if you can give us more details like which line is 268 it will be possible to find the reason!
i have problem to set in to c++ MACRO singletone function result .
this is what i have :
the macro
#define CCDICT_FOREACH(__dict__, __el__) \
CCDictElement* pTmp##__dict__##__el__ = NULL; \
if (__dict__) \
HASH_ITER(hh, (__dict__)->m_pElements, __el__, pTmp##__dict__##__el__)
and this is how i try to set it :
CCDictElement* pElement = NULL;
CCDICT_FOREACH(GameSingleTone::getInstance()->getGemsDictionary(), pElement)
{
}
the method getGemsDictionary() returns me:
CCDictionary*,gemsDictionary;
the compilation error im getting is (on the line of the MACRO):
error C2143: syntax error : missing ';' before '{'
but if i do :
CCDictionary* tempDictionary = CCDictionary::create();
tempDictionary = GameSingleTone::getInstance()->getGemsDictionary();
CCDICT_FOREACH(tempDictionary , pElement)
{
}
every thing is working .
why ?
Macros simply do text replacement. So when you do this:
CCDICT_FOREACH(GameSingleTone::getInstance()->getGemsDictionary(), pElement)
This line:
CCDictElement* pTmp##__dict__##__el__ = NULL; \
becomes this:
CCDictElement* pTmpGameSingleTone::getInstance()->getGemsDictionary()pElement = NULL;
Which is utter nonsense. This, on the other hand:
CCDICT_FOREACH(tempDictionary , pElement)
translates to this:
CCDictElement* pTmptempDictionarypElement = NULL;
Which is perfectly okay.
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'm working in visual studio with DirectX and today I've gotten some weird compiler errors that don't make any sense (to me at least)...
These are the errors I get:
error C2143: syntax error : missing ';' before '.'
error C2059: syntax error : ')'
I've double checked my code and didn't spot any typos/mistakes (I could be wrong...)
I'm hoping that someone can tell me what the error usually means and where to look...
I'll put some code below with the indication of the line where the errors occur (in case you want to check)
Extra info:
m_ImTexture2D is a member struct.
Vertex.PosTex is a struct within a struct
GameManager.cpp:
(231): error C2143: syntax error : missing ';' before '.'
(231): error C2143: syntax error : missing ';' before '.'
(232): error C2143: syntax error : missing ';' before '{'
(233): error C2143: syntax error : missing ';' before '}'
(233): error C2143: syntax error : missing ';' before ','
(234): error C2143: syntax error : missing ';' before '{'
(234): error C2143: syntax error : missing ';' before '}'
(234): error C2143: syntax error : missing ';' before ','
(235): error C2143: syntax error : missing ';' before '{'
(235): error C2143: syntax error : missing ';' before '}'
(235): error C2143: syntax error : missing ';' before ','
(237): error C2143: syntax error : missing ';' before '{'
(237): error C2143: syntax error : missing ';' before '}'
(237): error C2143: syntax error : missing ';' before ','
(238): error C2143: syntax error : missing ';' before '{'
(238): error C2143: syntax error : missing ';' before '}'
(238): error C2143: syntax error : missing ';' before ','
(239): error C2143: syntax error : missing ';' before '{'
(239): error C2143: syntax error : missing ';' before '}'
(246): error C2143: syntax error : missing ')' before '.'
(246): error C2143: syntax error : missing ';' before '.'
(246): error C2143: syntax error : missing ';' before '.'
(246): error C2059: syntax error : ')'
(249): error C2065: 'vertices' : undeclared identifier
bool GameManager::GMLoadImage(Image** ppImage, const char* pkcFilePath, ImageDesc* pImDesc)
{
(*ppImage) = new Image();
ID3D11ShaderResourceView** ppColorMap = (*ppImage)->GetppColorMap();
/// CREATE SHADER RESOURCE VIEW (from file) ///
HRESULT result = D3DX11CreateShaderResourceViewFromFileA(m_pDevice,
pkcFilePath,
0,
0,
ppColorMap,
0);
if (FAILED(result)) {
MessageBoxA(NULL,"Error loading ShaderResourceView from file","Error",MB_OK);
return false;
}
/// RECEIVE TEXTURE DESC ///
ID3D11Resource* pColorTex;
(*ppColorMap)->GetResource(&pColorTex);
((ID3D11Texture2D*)pColorTex)->GetDesc(&((*ppImage)->GetColorTexDesc()));
pColorTex->Release();
/// CREATE VERTEX BUFFER ///
D3D11_TEXTURE2D_DESC colorTexDesc = (*ppImage)->GetColorTexDesc();
float halfWidth = static_cast<float>(colorTexDesc.Width)/2.0f;
float halfHeight = static_cast<float>(colorTexDesc.Height)/2.0f;
/*231*/ Vertex.PosTex vertices[]=
/*232*/ {
/*233*/ {XMFLOAT3( halfWidth, halfHeight, 1.0f ), XMFLOAT2( 1.0f, 0.0f )},
/*234*/ {XMFLOAT3( halfWidth, -halfHeight, 1.0f ), XMFLOAT2( 1.0f, 1.0f )},
/*235*/ {XMFLOAT3( -halfWidth, -halfHeight, 1.0f ), XMFLOAT2( 0.0f, 1.0f )},
/*236*/
/*237*/ {XMFLOAT3( -halfWidth, -halfHeight, 1.0f ), XMFLOAT2( 0.0f, 1.0f )},
/*238*/ {XMFLOAT3( -halfWidth, halfHeight, 1.0f ), XMFLOAT2( 0.0f, 0.0f )},
/*239*/ {XMFLOAT3( halfWidth, halfHeight, 1.0f ), XMFLOAT2( 1.0f, 0.0f )}
};
D3D11_BUFFER_DESC vertexDesc;
ZeroMemory(&vertexDesc,sizeof(vertexDesc));
vertexDesc.Usage = D3D11_USAGE_DEFAULT;
vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
/*246*/ vertexDesc.ByteWidth = sizeof(Vertex.PosTex)*6;
D3D11_SUBRESOURCE_DATA resourceData;
/*249*/ resourceData.pSysMem = vertices;
ID3D11Buffer** ppVBuffer = (*ppImage)->GetppVertexBuffer();
result = m_pDevice->CreateBuffer(&vertexDesc,&resourceData,ppVBuffer);
if (FAILED(result)) {
MessageBoxA(NULL,"Error Creating VBuffer","Error",MB_OK);
return false;
}
/// SET POINTER TO IMAGEDESC
ImageDesc** ppThisImDesc = (*ppImage)->GetppImageDesc();
(*ppThisImDesc) = pImDesc;
return true;
}
DxTetris.cpp:
(27): error C2143: syntax error : missing ')' before '.'
(27): error C2143: syntax error : missing ';' before '.'
(27): error C2143: syntax error : missing ';' before '.'
(27): error C2059: syntax error : ')'
bool DxTetris::LoadContent()
{
GameManager::GMInitSingleton(m_pD3DDevice,m_pD3DContext,m_pBackBufferTarget);
m_ImTexture2DDesc.Topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
/*27*/m_ImTexture2DDesc.VertexSize = sizeof(Vertex.PosTex);
//.....(code goes on)
}
In C++, the scope resolution operator is ::, not .; consequently, you need to use Vertex::PosTex rather than Vertex.PosTex.