View Full Version : [C++] Problema funzione membro
Ho bisongo di far collaborare un analizzatore lessicale e uno grammaticale(Parser Generator) con una classe composta da me... in particolar modo l'analisi lessicale viene fatta dalla classe myparser.
Io devo costruire un oggetto della classe parser nella mia classe(che si chiama CIdentityDlg). Come devo procedere?
Spero di essere stato chiaro...Grazie...
devi aggiungere nella tua classe una variabile membro del tipo parser.
nel tuo .h, nella zona protected:
protected:
Cparser m_parser;
inserendo:
protected:
myparser m_parser;
Mi da i seguenti errori:
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2146: syntax error : missing ';' before identifier 'm_parser'
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'myparser' : missing storage-class or type specifiers
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'm_parser' : missing storage-class or type specifiers
IdentityDlg.cpp
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2146: syntax error : missing ';' before identifier 'm_parser'
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'myparser' : missing storage-class or type specifiers
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'm_parser' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.
Identity.exe - 6 error(s), 0 warning(s)
Per quale motivo?
hai incluso il file header della classe parser?
Si, ho aggiunto il file al progetto...
#include "myparser.h"
e poi ho aggiunto tale header anche nel mio progetto tramite il pulsante add to project...
non so cos'altro provare...è da due giorni che sono bloccato e non riesco a trovare soluzioni...cos'altro potrei fare?
Perché non ci fai vedere un po' del codice della classe ?
Questa è "myparser.h" generata automaticamente dall'analizzatore grammaticale
#ifndef _MYPARSER_H
#define _MYPARSER_H
#include <yycpars.h>
#define CORE 257
#define VIRGOLA 258
#define DELTA 259
#define PARENTESIAPERTA 260
#define PARENTESICHIUSA 261
#define NUMBER 262
/////////////////////////////////////////////////////////////////////////////
// myparser
#ifndef YYEXPPARSER
#define YYEXPPARSER
#endif
class YYEXPPARSER YYFAR myparser : public _YL yyfparser {
public:
myparser();
virtual ~myparser();
protected:
void yytables();
virtual void yyaction(int action);
#ifdef YYDEBUG
void YYFAR* yyattribute1(int index) const;
void yyinitdebug(void YYFAR** p, int count) const;
#endif
// attribute functions
virtual void yystacktoval(int index);
virtual void yyvaltostack(int index);
virtual void yylvaltoval();
virtual void yyvaltolval();
virtual void yylvaltostack(int index);
virtual void YYFAR* yynewattribute(int count);
virtual void yydeleteattribute(void YYFAR* attribute);
virtual void yycopyattribute(void YYFAR* dest, const void YYFAR* src, int count);
public:
#line 23 ".\\myparser.y"
// place any extra class members here
//int parse();
#line 75 "myparser.h"
};
#ifndef YYPARSERNAME
#define YYPARSERNAME myparser
#endif
#line 40 ".\\myparser.y"
#ifndef YYSTYPE
#define YYSTYPE int
#endif
#line 88 "myparser.h"
#endif
Pe creare un oggetto di questo tipo nella mia classe IdentityDlg.cpp dichiaro
#include "myparser.h"
e in IdentityDlg.h aggiungo sotto protected
protected:
myparser m_parser;
Compilando mi da i seguenti errori:
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2146: syntax error : missing ';' before identifier 'm_parser'
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'myparser' : missing storage-class or type specifiers
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'm_parser' : missing storage-class or type specifiers
IdentityDlg.cpp
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2146: syntax error : missing ';' before identifier 'm_parser'
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'myparser' : missing storage-class or type specifiers
C:\Documents and Settings\Pa_co\Desktop\identity + Linguaggio\Identity\IdentityDlg.h(244) : error C2501: 'm_parser' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.
Identity.exe - 6 error(s), 0 warning(s)
dove sbaglio?
#include "myparser.h" devi includerla nel tuo .h
Spostando l'include nel .h mi da questi errori....
Deleting intermediate files and output files for project 'Identity - Win32 Release'.
--------------------Configuration: Identity - Win32 Release--------------------
Performing Custom Build Step on .\mylexer.l
Performing Custom Build Step on .\myparser.y
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
Identity.cpp
IdentityDlg.cpp
Generating Code...
Linking...
Identity.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall myparser::~myparser(void)" (??1myparser@@UAE@XZ)
IdentityDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall myparser::~myparser(void)" (??1myparser@@UAE@XZ)
IdentityDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall myparser::myparser(void)" (??0myparser@@QAE@XZ)
Release/Identity.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Identity.exe - 4 error(s), 0 warning(s)
sembra quasi che manchino le implementazioni nel file myparser.h del construttore e del distruttore della classe myparser.
mhhh ma hai incluso la classe myparser nel tuo progetto? viene compilata?
Devi aggiungere il ,cpp al tuo progetto. Infatti non stai compilando myparser.cpp.
Ho risolto, grazie mille per tutti i consigli...sono stati utilissimi...senza non ce l'avrei mai fatta...i problemi erano due...
il primo che non avevo incluso il .cpp nel progetto(pensavo che includere l'header bastasse)
il secondo era che utilizzavo la libreria sbagliata...
adesso sembra funzionare...
Grazie ancora...:D
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.