CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2013
    Posts
    5

    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

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    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

  3. #3
    Join Date
    Mar 2013
    Posts
    5

    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

  4. #4
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Macro to template

    Google yields a list:
    http://www.google.com/search?q=using...in+header+file
    This post: http://stackoverflow.com/questions/4...-bad-idea-in-c
    gives some good explanations, I think.

    HTH,
    Richard

  5. #5
    Join Date
    Mar 2013
    Posts
    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
  •  





Click Here to Expand Forum to Full Width

Featured