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

  • SEARCH
  • Home
  • 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 7685455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:15:19+00:00 2026-05-31T19:15:19+00:00

I’m getting an end of file before the left brace was matched while trying

  • 0

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?

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…

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!

EDIT:

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.

    template <typename Type>
    void PQueue<Type>::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->blockTArray = new Type[MaxElementsPerBlock];
            newBlock->capacity = MaxElementsPerBlock;
            newBlock->next = NULL;
            newBlock->head = 0;
            newBlock->blockTArray[0] = element;
            newBlock->tail = 1;
            listHead = newBlock;
        }

        //case 2: element > blockTArray[0]
        else if (element >= runner->blockTArray[0]) { 
            //CASE 2A
            if (runner->tail < runner->capacity) {
                for (int i = runner->tail; i > 0; i--) { //iterate through array
                    runner->blockTArray[i] = runner->blockTArray[i-1]; //move everything 1 to right
                }
                runner->blockTArray[0] = element; //insert "element" at front
                runner->tail++; //increment tail
            }
            //CASE 2B
            else {
                blockT *newBlock = new blockT;
                newBlock->next = runner;
                newBlock->blockTArray = new Type[MaxElementsPerBlock];
                newBlock->blockTArray[0] = element;
                newBlock->tail = 1;
                newBlock->head = 0;
                newBlock->capacity = MaxElementsPerBlock;
                listHead = newBlock;
            }
        }

        //case 3: if runner is less than runner array[head] and array is NOT full
        else if (element < runner->blockTArray[0]) {
            //TRAVERSE TO FIND END OR BLOCKTARR > ELEMENT
            blockT *back;
            while (true) {
                if (runner->next == NULL || runner->blockTArray[0] <= element) break;
                else {
                    back = runner;
                    runner = runner->next;
                }
            }

            //EQUAL TO ELEMENT
            if (runner->blockTArray[0] == element) {
                //INSERT ON THAT ARR IF SPACE
                if (runner->tail < runner->capacity) {
                    for (int i = runner->tail; i > 0; i--) { //iterate through array
                        runner->blockTArray[i] = runner->blockTArray[i-1]; //move 1 right
                    }
                    runner->blockTArray[0] = element; //insert "element" at front
                    runner->tail++;
                }
                //ELSE MAKE NEW BLOCK AND PUT 1/2 ELEMENTS ON IT
                else {
                    blockT *newBlock = new blockT;
                    newBlock->blockTArray = new Type[MaxElementsPerBlock];
                    newBlock->capacity = MaxElementsPerBlock;
                    newBlock->blockTArray[0] = element;
                    newBlock->tail = 1;
                    newBlock->head = 0;
                    newBlock->next = runner; //set this new block's "next" = to cell runner was  pointing at
                    back->next = newBlock; //take the cell the runner was stored in (back->next) and set it to new block's address
                }
            }
            //if we stopped because the next arr[0] is smaller, use ->back to place on previous cell 
            else if (runner->blockTArray[0] < element) {
                //if element is bigger than or equal to current arr and -> isn't full, add to front of ->
                if (element == back->blockTArray[back->tail - 1] && runner->tail < runner->capacity) {
                    for (int i = runner->tail; i > 0; i--) { //iterate through array
                        runner->blockTArray[i] = runner->blockTArray[i-1]; //move everything 1 to right
                    }
                    runner->blockTArray[0] = element; //insert "element" at front
                    runner->tail++;
                }

                else if (element == back->blockTArray[back->tail - 1] && runner->tail == runner->capacity) {
                    if (back->tail == back->capacity) {
                        blockT *newBlock = new blockT;
                        newBlock->blockTArray = new Type[MaxElementsPerBlock];
                        newBlock->capacity = MaxElementsPerBlock;
                        newBlock->blockTArray[0] = element;
                        newBlock->tail = 1;
                        newBlock->head = 0;
                        newBlock->next = runner; //set this new block's "next" = to cell runner was pointing at
                        back->next = newBlock;
                    }
                    else {
                        for (int i = 0, i < back->tail; i++) {
                            if (element <= back->blockTArray[i]) {
                                for (int x = runner->tail; x >= i; x--) { //iterate through array
                                    runner->blockTArray[x] = runner->blockTArray[x-1]; //move everything 1 to right
                                }
                                runner->blockTArray[i] = element; //insert "element" at front
                            }
                        }
                    }
                }
                else if (back->tail == back->capacity) {
                    for (int i = 0, i < back->tail; i++) {
                        if (element <= back->blockTArray[i]) {
                            blockT *newBlock = new blockT;
                            newBlock->blockTArray = new Type[MaxElementsPerBlock];
                            newBlock->capacity = MaxElementsPerBlock;
                            newBlock->head = 0;
                            for (int x = (MaxElementsPerBlock - (i+3)), z = runner->tail;
                                x >= 0, z > i; x--, z--) {
                                newblock->blockTArray[x] = runner->blockTArray[z - 1];
                            }
                            runner->blockTArray[i + 1] = element;
                            runner->tail = i + 2; //you're two ahead in this case since you wrote to i+1
                            newBlock->tail = i + 1; //because you're one ahead of the element you inserted 
                            back->next = newBlock;
                            newBlock->next = runner;
                            break;
                        }
                    }
                }
            }
            //NULL CASE if next is null but current arr isn't full, shuffle and insert here
            else if (runner->next == NULL && runner->tail < runner->capacity) {
                for (int i = 0; i < runner->tail; i++) {
                    if (element <= runner->blockTArray[i]) {
                        for (int x = runner->tail - 1; x > blockTArray[i]; x--) {
                            runner->blockTArray[x + 1] = runner->blockTArray[x];
                        }
                        runner->tail++;
                    }
                }
            }
            else if (runner->next == NULL && runner->tail == runner->capacity) {
                for (int i = 0, i < back->tail; i++) {
                    if (element <= runner->blockTArray[i]) {
                        blockT *newBlock = new blockT;
                        newBlock->blockTArray = new Type[MaxElementsPerBlock];
                        newBlock->capacity = MaxElementsPerBlock;
                        newBlock->head = 0;
                        for (int x = (MaxElementsPerBlock - (i+3)), z = runner->tail;
                            x >= 0, z > i; x--, z--) {
                            newblock->blockTArray[x] = runner->blockTArray[z - 1];
                        }
                        runner->blockTArray[i + 1] = element;
                        runner->tail = i + 2; //you're two ahead in this case since you wrote to i+1
                        newBlock->tail = i + 1; //because you're one ahead of the element you inserted 
                        runner->next = newBlock;
                        newBlock->next = NULL;
                        break;
                    }
                }
            }
            }

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…

  • 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-31T19:15:20+00:00Added an answer on May 31, 2026 at 7:15 pm

    If you have absolutely no idea what has changed since it compiled, disable most of the source code by placing

    #if 0
    
    #endif
    

    around the code. Test compile to make sure the error is gone. If it is, reduce the amount of code which is commented out and try again. It should be a fairly quick binary search (5-10 iterations for a large module) which identifies the offending brace.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.