Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:54:06+00:00 2026-05-23T16:54:06+00:00

This code gives me many headaches when compiling under GCC ARM. I am using

  • 0

This code gives me many headaches when compiling under GCC ARM. I am using it fine with MSVC++ compiler 2010. I get compile errors like:

Error 1 error : expected ‘;’ before ‘i’ C:\Users\Ryan\Desktop\droplets\source\MultiList.h 62

Why won’t my templated code compile using GCC?

#ifndef MULTILIST_H
#define MULTILIST_H

#include <list>
#include <fstream>

using namespace std;

/*
 A list of lists
 */
template <typename E> 
class MultiList {

protected:
    list<list<E>*>      m_lists;
    list<E>             *m_pCurrList;

public:

    MultiList();
    ~MultiList();
    /*
    Starts a new list internally, given the first element
    */
    void BeginNewList(E firstElement);

    /*
    Adds an element to the current list
    */
    void AddElement(E newElement);

    /*
    Removes a given element from it's place in one of the lists,
    splitting that list into two lists internally.
    */
    void RemoveElement(E element);

    /*
    Returns a list of all element lists
    */
    list<list<E>*> *GetLists() {
        return &m_lists;
    };

    /*
    Return the list that's currently being populated with AddElement()
    */
    list<E>* GetCurrentList() {
        return m_pCurrList;
    };

};

template<typename E>
MultiList<E>::MultiList() {
    m_pCurrList = NULL;
}

template<typename E>
MultiList<E>::~MultiList() {
    for(list<list<E>*>::iterator i = m_lists.begin(); i != m_lists.end(); i++) {
        list<E>::iterator j;
        for(j = (*i)->begin(); j != (*i)->end(); j++) {
            SDELETE(*j)
        }
        SDELETE(*i)
    }
}

/*
Starts a new list internally, given the first element
*/
template<typename E>
void MultiList<E>::BeginNewList(E firstElement) {
    list<E> *newlist = new(list<E>);
    newlist->push_back(firstElement);
    m_lists.push_back(newlist);
    m_pCurrList = newlist;
}

/*
Adds an element to the current list
*/
template<typename E>
void MultiList<E>::AddElement(E newElement) {
    m_pCurrList->push_back(newElement);
}

/*
Removes a given element from it's place in one of the lists,
splitting that list into two lists internally.
*/
template<typename E>
void MultiList<E>::RemoveElement(E element) {
    list<E>* found = NULL;
    list<E>::iterator foundIT = NULL;

    // find which list 'element' is in
    for(list<list<E>*>::iterator i = m_lists.begin(); i != m_lists.end(); i++) {
        list<E>::iterator j;
        for(j = (*i)->begin(); j != (*i)->end(); j++) {
            E listElement = (*j);
            if(listElement == element) {
                found = (*i);
                foundIT = j;
                break;
            }
        }
        if (j != (*i)->end()) break; // we breaked out of the inner loop
    }
    // now erase it and split the list
    if (found) {
        list<E>::iterator next = found->erase(foundIT);
        list<E> *newlist = new(list<E>);
        m_lists.push_back(newlist);
        newlist->splice(newlist->begin(), *found, next, found->end());
        SDELETE(element)
    }
}

#endif
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:54:07+00:00Added an answer on May 23, 2026 at 4:54 pm

    It won’t compile because it is chock full o’errors:

    g++ -Wall /tmp/junk.c
    /tmp/junk.c: In destructor ‘MultiList<E>::~MultiList()’:
    /tmp/junk.c:62:9: error: need ‘typename’ before ‘std::list<std::list<E>*>::iterator’ because ‘std::list<std::list<E>*>’ is a dependent scope
    /tmp/junk.c:62:34: error: expected ‘;’ before ‘i’
    /tmp/junk.c:62:55: error: ‘i’ was not declared in this scope
    /tmp/junk.c:63:9: error: need ‘typename’ before ‘std::list<E>::iterator’ because ‘std::list<E>’ is a dependent scope
    /tmp/junk.c:63:27: error: expected ‘;’ before ‘j’
    /tmp/junk.c:64:13: error: ‘j’ was not declared in this scope
    /tmp/junk.c:65:23: error: there are no arguments to ‘SDELETE’ that depend on a template parameter, so a declaration of ‘SDELETE’ must be available
    /tmp/junk.c:65:23: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
    /tmp/junk.c:66:9: error: expected ‘;’ before ‘}’ token
    /tmp/junk.c:67:19: error: there are no arguments to ‘SDELETE’ that depend on a template parameter, so a declaration of ‘SDELETE’ must be available
    /tmp/junk.c:68:5: error: expected ‘;’ before ‘}’ token
    /tmp/junk.c: In member function ‘void MultiList<E>::RemoveElement(E)’:
    /tmp/junk.c:97:5: error: need ‘typename’ before ‘std::list<E>::iterator’ because ‘std::list<E>’ is a dependent scope
    /tmp/junk.c:97:23: error: expected ‘;’ before ‘foundIT’
    /tmp/junk.c:100:9: error: need ‘typename’ before ‘std::list<std::list<E>*>::iterator’ because ‘std::list<std::list<E>*>’ is a dependent scope
    /tmp/junk.c:100:34: error: expected ‘;’ before ‘i’
    /tmp/junk.c:100:55: error: ‘i’ was not declared in this scope
    /tmp/junk.c:101:9: error: need ‘typename’ before ‘std::list<E>::iterator’ because ‘std::list<E>’ is a dependent scope
    /tmp/junk.c:101:27: error: expected ‘;’ before ‘j’
    /tmp/junk.c:102:13: error: ‘j’ was not declared in this scope
    /tmp/junk.c:106:17: error: ‘foundIT’ was not declared in this scope
    /tmp/junk.c:114:9: error: need ‘typename’ before ‘std::list<E>::iterator’ because ‘std::list<E>’ is a dependent scope
    /tmp/junk.c:114:27: error: expected ‘;’ before ‘next’
    /tmp/junk.c:117:51: error: ‘next’ was not declared in this scope
    /tmp/junk.c:119:5: error: expected ‘;’ before ‘}’ token
    

    Use -Wall and understand what its complaints are. A better question might be why did MSVC not complain?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Compiling this code snippet with gcc (4.5) and as many -Wall, -Wextra, -Wuninitialized type
Please I have this code which gives me many errors: //Neuron.h File #ifndef Neuron_h
This code gives you an error in the error list of VS 2010: let
This code gives me an empty result. I expect it to print out the
Can anyone explain why this code gives the error: error C2039: 'RT' : is
This code in JS gives me a popup saying i think null is a
This very simple code gives me tons of errors: #include <iostream> #include <string> int
This piece of code gives a syntax error at the colon of elif process.loop(i,
In this code, for vector size, n >=32767, it gives segmentation fault, but upto
The code below gives me this mysterious error, and i cannot fathom it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.