-
March 22nd, 2013, 05:30 PM
#1
Macro to template
Hello, I have this macro, that expands to some methods of my class:
Code:
#define POPULAR_COMBO_FILTRO_COM_BASE(classeTabela) \
void VisualizadorLogsFrame::PopularComboFiltroCom ## classeTabela (bool limparTexto) { \
long from, to; \
m_cbxDetalhe->GetSelection(&from, &to); \
wxString conteudoCombo = m_cbxDetalhe->GetValue(); \
m_cbxDetalhe->Clear(); \
if (!limparTexto) { \
m_cbxDetalhe->SetValue(conteudoCombo); \
m_cbxDetalhe->SetSelection(from, to); \
} \
int pos = 0; \
for (list<classeTabela*>::iterator linha = m_lista ## classeTabela ->begin(); linha != m_lista ## classeTabela ->end(); linha++) { \
wxIntClientData* idInfo = new wxIntClientData(); \
idInfo->m_valor = (*linha)->m_id; \
wxString nome = (*linha)->m_name; \
if ( (m_cbxDetalhe->GetValue().size() == 0) || (nome.MakeUpper().Find(m_cbxDetalhe->GetValue().MakeUpper()) != wxNOT_FOUND) ) {
m_cbxDetalhe->Insert((*linha)->m_name, pos, idInfo); pos++;
};
};
};
and I want to use a template instead of it. So I had translated it to:
Code:
template<class T> void PopularComboFiltroComNomeavel(list<CLASSE_TABELA*>* lista, bool limparTexto) {
long from, to;
m_cbxDetalhe->GetSelection(&from, &to);
wxString conteudoCombo = m_cbxDetalhe->GetValue();
m_cbxDetalhe->Clear();
if (!limparTexto) {
m_cbxDetalhe->SetValue(conteudoCombo);
m_cbxDetalhe->SetSelection(from, to);
}
int pos = 0;
for (list< CLASSE_TABELA *>::iterator linha = lista->begin(); linha != lista->end(); linha++) {
wxIntClientData* idInfo = new wxIntClientData();
idInfo->m_valor = (*linha)->m_id;
wxString nome = (*linha)->m_name;
if ( (m_cbxDetalhe->GetValue().size() == 0) || (nome.MakeUpper().Find(m_cbxDetalhe->GetValue().MakeUpper()) != wxNOT_FOUND) ) {
m_cbxDetalhe->Insert((*linha)->m_name, pos, idInfo); pos++;
};
};
};
but I get a compile error on this line:
Code:
for (list< CLASSE_TABELA *>::iterator linha = lista->begin(); linha != lista->end(); linha++) {
what am I doing wrong ? the error is:
VisualizadorLogsMain.h:174: error: expected ‘;’ before ‘linha’
VisualizadorLogsMain.h:174: error: ‘linha’ was not declared in this scope
-Nelson
-
March 23rd, 2013, 01:39 AM
#2
Re: Macro to template
Try this:
Code:
for (typename list< CLASSE_TABELA *>::iterator linha = lista->begin(); linha != lista->end(); linha++) {
There are other issues, such as you should use pre-increment instead of post-increment in the loop construct:
Code:
for (typename list< CLASSE_TABELA *>::iterator linha = lista->begin(); linha != lista->end(); ++linha) {
Also, you shouldn't have "using namespace std" in a header file. I suspect this, since I see only "list" instead of "std::list" in your code.
Regards,
Paul McKenzie
-
March 26th, 2013, 08:23 AM
#3
Re: Macro to template
Thanks Paul, it worked. Can you tell me more on why I shouldn't use "using namespace std" in a header file, or point me to some article where I can read about it ?
-Nelson
-
March 26th, 2013, 08:34 AM
#4
-
March 26th, 2013, 08:36 AM
#5
Re: Macro to template
OK thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|