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 7851731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:15:10+00:00 2026-06-02T19:15:10+00:00

I am trying to build a vector using a function that I am calling

  • 0

I am trying to build a vector using a function that I am calling vector<Competition> CompPop(). I want to return the vector info which is a type vector<Competition>. Below is my code for the function returning the vector and the header for my Competition class.

I’m getting the following errors (I’m using Visual Studio and the error message are very basic, leaving me guessing as to what I am actually doing wrong):

-error C2065: ‘Competition’ : undeclared identifier

‘CompPop’ uses undefined class ‘std::vector’

‘Competition’ : undeclared identifier

error C2133: ‘info’ : unknown size

error C2512: ‘std::vector’ : no appropriate default constructor available

error C2065: ‘Competition’ : undeclared identifier

error C2146: syntax error : missing ‘;’ before identifier ‘temp’

error C3861: ‘temp’: identifier not found

error C2678: binary ‘[‘ : no operator found which takes a left-hand operand of type ‘std::vector’ (or there is no acceptable conversion)


    #pragma once

    #include <fstream>
    #include <sstream>
    #include <iostream>
    #include <string>
    #include <vector>
    #include "LogIn.h"
    #include "Registration.h"
    #include "Tree.h"
    #include "PriorityQueue.h"
    #include "Events.h"
    #include "Competition.h"
    using namespace std;

    vector<Competition> CompPop()
    {
        ifstream myfile("Results.txt");

        string line, tcomp, tleader, tfollower, tevents, tplacement;
        vector<Competition> info;
        istringstream instream;
        if(myfile.is_open())
        {
         int i = 0; // finds first line
         int n = 0; // current vector index
         int space;
         while(!myfile.eof())
         {
        getline(myfile,line);

        if(line[i] == '*')
        {
            space = line.find_first_of(" ");
                
            tleader = line.substr(0+1, space);
            tfollower = line.substr(space + 1, line.size());

        }
        else
        {
            if(line[i] == '-')
            {
                tcomp = line.substr(1, line.size());
                Competition temp(tcomp, tleader, tfollower);
                info[n] = temp;
            }
            else
            {
                if(!line.empty())
                {
                    line = line;

                    space = line.find_first_of(",");
                    tevents = line.substr(0, space);
                    tplacement = line.substr(space + 2,     line.size());
                    info[n].pushEvents(tevents,tplacement);
                }
                if(line.empty())
                {
                    n++;
                }
            }
           }
            }
        }
       else
       {
        cout << "Unable to open file";
       }

       myfile.close();

      return info;
    }

my Competition header:

    #pragma once

    #include <fstream>
    #include <sstream>
    #include <iostream>
    #include <string>
    #include <vector>
    #include "LogIn.h"
    #include "Registration.h"
    #include "Tree.h"
    #include "PriorityQueue.h"
    #include "Events.h"
    #include "CompPop.h"
    using namespace std;

    struct Competition
    {
         public:

     Competition(string compName, string lead, string follow)
     {
    Name = compName;
    Leader = lead;
    Follower = follow;
     }

     void pushEvents(string name, string place)
     {
    Events one(name, place);
    Eventrandom.push_back(one);
     }

     string GetName()
     {
    return Name;
     }

     string GetLeader()
     {
    return Leader;
     }

     string GetFollow()
     {
    return Follower;
     }

     string GetEvent()
     {
    return Event;
     }

     string GetScore()
     {
    return Score;
     }

      ~Competition();

     private:
   string Name, Leader, Follower, Event, Score;

   vector<Events> Eventrandom;
     };
  • 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-06-02T19:15:11+00:00Added an answer on June 2, 2026 at 7:15 pm

    It looks like you’re not #includeing the header for Competition in your source file.

    As an aside, it also looks like you’re doing using namespace std; in your header. This is not a good practice.

    Edit based on updated info:

    This is a circular dependency issue.

    If you simply forward declare Competition and declare CompPop in CompPop.h, and add the implementation of CompPop to a CompPop.cpp, you’ll break the cycle.

    So change CompPop.h to:

    #pragma once
    #include <vector>
    struct Competition;
    std::vector<Competition> CompPop();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a polynomial function generator, so that it takes a vector
I am trying build an AST for the below grammer using ANTLR condition_in :
I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
So, I am trying to build a two-dimensional vector that will hold indexes for
I'm trying to write a function that takes a 2D vector as an argument.
I'm trying to build a crossbrowser vector application, and to do so am using
I'm trying build a method which returns the shortest path from one node to
I'm trying to build an application using AIR 2's new NativeProcess API's going from
I'm trying to build a grid the size of the browser window that has
I am trying to build a simple openGL and SDL program that just refuses

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.