Note that there are some explanatory texts on larger screens.

plurals
  1. POleft brace "{" error in c++
    text
    copied!<p>I'm getting an "end of file before the left brace was matched" while trying to compile a template class that I created. When I double click on the error message in Visual Studio it takes me to the top of the "main" file where I'm trying to run the code. When I go to the .cpp file for the class, all the member functions are minimized except for one...which makes me think that's where the problem is? Is there a quick way to find where missing brace is? </p> <p>Another reason I think it exists in this one particular member function is that at the bottom of the declaration, as I'm adding closing braces (I'm adding them from a code block that is indented like 5 spaces), normally Visual Studio puts them at the correct indentation as you type one and push enter, type one and push enter, etc. but in this case it stops indenting about two "tab" over and will just keep putting them on the same indentation as I continue to type "}" and press enter, type "}" and press enter...</p> <p>The code for the member function is complicated and long enough that it's hard to go through and even though I have about 5 times, I can't find where anything is missing. Is there a trick to this? Could I be looking in the right place? Thanks!</p> <p>EDIT:</p> <p>I didn't post it because, to be honest, it's ugly as hell. I'm implementing my first real class and it's a template class - linked list of array's. It's waay too long and messy and I probably should have some better abstraction within. In addition to a little self conciousness, I also figured you guys would take one look at the post and move on, I know I'd be tempted to... Also NOTE: I didn't comment everything because much of the code get's repetitive, only under different initial conditions. </p> <pre><code> template &lt;typename Type&gt; void PQueue&lt;Type&gt;::enqueue(Type element) { blockT *runner = listHead; //BE CAREFUL - duplicate so as not to eff with listHead - used deep //case 1: if this is the first element entered if (listHead == NULL) { blockT *newBlock = new blockT; newBlock-&gt;blockTArray = new Type[MaxElementsPerBlock]; newBlock-&gt;capacity = MaxElementsPerBlock; newBlock-&gt;next = NULL; newBlock-&gt;head = 0; newBlock-&gt;blockTArray[0] = element; newBlock-&gt;tail = 1; listHead = newBlock; } //case 2: element &gt; blockTArray[0] else if (element &gt;= runner-&gt;blockTArray[0]) { //CASE 2A if (runner-&gt;tail &lt; runner-&gt;capacity) { for (int i = runner-&gt;tail; i &gt; 0; i--) { //iterate through array runner-&gt;blockTArray[i] = runner-&gt;blockTArray[i-1]; //move everything 1 to right } runner-&gt;blockTArray[0] = element; //insert "element" at front runner-&gt;tail++; //increment tail } //CASE 2B else { blockT *newBlock = new blockT; newBlock-&gt;next = runner; newBlock-&gt;blockTArray = new Type[MaxElementsPerBlock]; newBlock-&gt;blockTArray[0] = element; newBlock-&gt;tail = 1; newBlock-&gt;head = 0; newBlock-&gt;capacity = MaxElementsPerBlock; listHead = newBlock; } } //case 3: if runner is less than runner array[head] and array is NOT full else if (element &lt; runner-&gt;blockTArray[0]) { //TRAVERSE TO FIND END OR BLOCKTARR &gt; ELEMENT blockT *back; while (true) { if (runner-&gt;next == NULL || runner-&gt;blockTArray[0] &lt;= element) break; else { back = runner; runner = runner-&gt;next; } } //EQUAL TO ELEMENT if (runner-&gt;blockTArray[0] == element) { //INSERT ON THAT ARR IF SPACE if (runner-&gt;tail &lt; runner-&gt;capacity) { for (int i = runner-&gt;tail; i &gt; 0; i--) { //iterate through array runner-&gt;blockTArray[i] = runner-&gt;blockTArray[i-1]; //move 1 right } runner-&gt;blockTArray[0] = element; //insert "element" at front runner-&gt;tail++; } //ELSE MAKE NEW BLOCK AND PUT 1/2 ELEMENTS ON IT else { blockT *newBlock = new blockT; newBlock-&gt;blockTArray = new Type[MaxElementsPerBlock]; newBlock-&gt;capacity = MaxElementsPerBlock; newBlock-&gt;blockTArray[0] = element; newBlock-&gt;tail = 1; newBlock-&gt;head = 0; newBlock-&gt;next = runner; //set this new block's "next" = to cell runner was pointing at back-&gt;next = newBlock; //take the cell the runner was stored in (back-&gt;next) and set it to new block's address } } //if we stopped because the next arr[0] is smaller, use -&gt;back to place on previous cell else if (runner-&gt;blockTArray[0] &lt; element) { //if element is bigger than or equal to current arr and -&gt; isn't full, add to front of -&gt; if (element == back-&gt;blockTArray[back-&gt;tail - 1] &amp;&amp; runner-&gt;tail &lt; runner-&gt;capacity) { for (int i = runner-&gt;tail; i &gt; 0; i--) { //iterate through array runner-&gt;blockTArray[i] = runner-&gt;blockTArray[i-1]; //move everything 1 to right } runner-&gt;blockTArray[0] = element; //insert "element" at front runner-&gt;tail++; } else if (element == back-&gt;blockTArray[back-&gt;tail - 1] &amp;&amp; runner-&gt;tail == runner-&gt;capacity) { if (back-&gt;tail == back-&gt;capacity) { blockT *newBlock = new blockT; newBlock-&gt;blockTArray = new Type[MaxElementsPerBlock]; newBlock-&gt;capacity = MaxElementsPerBlock; newBlock-&gt;blockTArray[0] = element; newBlock-&gt;tail = 1; newBlock-&gt;head = 0; newBlock-&gt;next = runner; //set this new block's "next" = to cell runner was pointing at back-&gt;next = newBlock; } else { for (int i = 0, i &lt; back-&gt;tail; i++) { if (element &lt;= back-&gt;blockTArray[i]) { for (int x = runner-&gt;tail; x &gt;= i; x--) { //iterate through array runner-&gt;blockTArray[x] = runner-&gt;blockTArray[x-1]; //move everything 1 to right } runner-&gt;blockTArray[i] = element; //insert "element" at front } } } } else if (back-&gt;tail == back-&gt;capacity) { for (int i = 0, i &lt; back-&gt;tail; i++) { if (element &lt;= back-&gt;blockTArray[i]) { blockT *newBlock = new blockT; newBlock-&gt;blockTArray = new Type[MaxElementsPerBlock]; newBlock-&gt;capacity = MaxElementsPerBlock; newBlock-&gt;head = 0; for (int x = (MaxElementsPerBlock - (i+3)), z = runner-&gt;tail; x &gt;= 0, z &gt; i; x--, z--) { newblock-&gt;blockTArray[x] = runner-&gt;blockTArray[z - 1]; } runner-&gt;blockTArray[i + 1] = element; runner-&gt;tail = i + 2; //you're two ahead in this case since you wrote to i+1 newBlock-&gt;tail = i + 1; //because you're one ahead of the element you inserted back-&gt;next = newBlock; newBlock-&gt;next = runner; break; } } } } //NULL CASE if next is null but current arr isn't full, shuffle and insert here else if (runner-&gt;next == NULL &amp;&amp; runner-&gt;tail &lt; runner-&gt;capacity) { for (int i = 0; i &lt; runner-&gt;tail; i++) { if (element &lt;= runner-&gt;blockTArray[i]) { for (int x = runner-&gt;tail - 1; x &gt; blockTArray[i]; x--) { runner-&gt;blockTArray[x + 1] = runner-&gt;blockTArray[x]; } runner-&gt;tail++; } } } else if (runner-&gt;next == NULL &amp;&amp; runner-&gt;tail == runner-&gt;capacity) { for (int i = 0, i &lt; back-&gt;tail; i++) { if (element &lt;= runner-&gt;blockTArray[i]) { blockT *newBlock = new blockT; newBlock-&gt;blockTArray = new Type[MaxElementsPerBlock]; newBlock-&gt;capacity = MaxElementsPerBlock; newBlock-&gt;head = 0; for (int x = (MaxElementsPerBlock - (i+3)), z = runner-&gt;tail; x &gt;= 0, z &gt; i; x--, z--) { newblock-&gt;blockTArray[x] = runner-&gt;blockTArray[z - 1]; } runner-&gt;blockTArray[i + 1] = element; runner-&gt;tail = i + 2; //you're two ahead in this case since you wrote to i+1 newBlock-&gt;tail = i + 1; //because you're one ahead of the element you inserted runner-&gt;next = newBlock; newBlock-&gt;next = NULL; break; } } } } </code></pre> <p>You can see at end the double } }. Believe it or not it's taken me a while to think through this and write this code. I'd like it to be cleaner, more professional, but I'm not sure the best ways to go about that. Abstraction? Do you guys use anything in addition to stock Visual Studio? Any installed environments? I just saw a post about the "Artistic Style 2.02." Worthwhile? Thanks for subjecting your eyes to this...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload