Note that there are some explanatory texts on larger screens.

plurals
  1. POin compiling c++ console my program, i get an error in the included vector header file, is it possible?
    primarykey
    data
    text
    <p>this is the full error message</p> <pre><code>&gt; In file included from &gt; c:\mingw\bin\../lib/gcc/mingw32/4.7.2/include/c++/vector:63:0, &gt; from PlayerDatabase.h:4, &gt; from PlayerDatabase.cpp:6: c:\mingw\bin\../lib/gcc/mingw32/4.7.2/include/c++/bits/stl_construct.h: &gt; In function 'void std::_Construct(_T1*, const _T2&amp;)': &gt; c:\mingw\bin\../lib/gcc/mingw32/4.7.2/include/c++/bits/stl_construct.h:85:13: &gt; error: expected type-specifier before 'static_cast' &gt; c:\mingw\bin\../lib/gcc/mingw32/4.7.2/include/c++/bits/stl_construct.h:85:13: &gt; error: expected ')' before 'static_cast' &gt; c:\mingw\bin\../lib/gcc/mingw32/4.7.2/include/c++/bits/stl_construct.h:85:13: &gt; error: expected ';' before 'static_cast' </code></pre> <p>the file included at PlayerDatabase.h:4 is the vector header file </p> <p>I have used a dynamic cast in my cpp file, to change pitcher and hitter pointers to a base class baseballplayer pointers before inserting them through push_baxk() into the vector, is that the problem?</p> <p>this is the playerdatabase.h file</p> <pre><code>#include &lt;vector&gt; #include "BaseballPlayer.h" #include "Hitter.h" #include "Pitcher.h" </code></pre> <p>// this is the playerdatabase class definition</p> <pre><code>class PlayerDatabase { public: PlayerDatabase(); PlayerDatabase(PlayerDatabase&amp;); PlayerDatabase&amp; operator= (PlayerDatabase&amp;); ~PlayerDatabase(); void print_team(std::ofstream&amp;); void load_team(std::ifstream&amp;); void create_good_team(); void create_small_team(); int get_team_count(); private: std::vector&lt;BaseballPlayer*&gt; team; }; </code></pre> <p>and this is the playerdatabase.cpp</p> <pre><code>#include &lt;iomanip&gt; #include "cppMemDbg.h" #include "PlayerDatabase.h" const char HITTER='H'; const char PITCHER='P'; const int REDUCE_BY=4; </code></pre> <p>// the default constructor without arguments</p> <pre><code>PlayerDatabase::PlayerDatabase(){ </code></pre> <p>}</p> <p>// the copy constructor</p> <pre><code>PlayerDatabase::PlayerDatabase(PlayerDatabase&amp; right){ std::vector&lt;BaseballPlayer*&gt;::iterator begin, end; begin=right.team.begin(); end=right.team.end(); while (begin!=end){ Pitcher* pPlayer= dynamic_cast&lt;Pitcher*&gt;(*begin); if (pPlayer){ Pitcher* pitcher= new Pitcher(*pPlayer); team.push_back(dynamic_cast&lt;BaseballPlayer*&gt;(pitcher)); } else{ Hitter* hPlayer= dynamic_cast&lt;Hitter*&gt;(*begin); Hitter* hitter= new Hitter(*hPlayer); team.push_back(dynamic_cast&lt;BaseballPlayer*&gt;(hitter)); } begin++; } </code></pre> <p>}</p> <p>// the assignment operator </p> <pre><code>PlayerDatabase&amp; PlayerDatabase::operator= (PlayerDatabase&amp; right){ if (team==right.team) return *this; else { std::vector&lt;BaseballPlayer*&gt;::iterator begin, end; begin=right.team.begin(); end=right.team.end(); while (begin!=end){ Pitcher* pPlayer= dynamic_cast&lt;Pitcher*&gt;(*begin); if (pPlayer){ Pitcher* pitcher= new Pitcher(*pPlayer); BaseballPlayer* bplayer= dynamic_cast&lt;BaseballPlayer*&gt;(pitcher); team.push_back(bplayer); } else{ Hitter* hPlayer= dynamic_cast&lt;Hitter*&gt;(*begin); Hitter* hitter= new Hitter(*hPlayer); BaseballPlayer* bplayer= dynamic_cast&lt;BaseballPlayer*&gt;(hitter); team.push_back(bplayer); } begin++; } } return *this; </code></pre> <p>}</p> <p>// the destructor</p> <pre><code>PlayerDatabase::~PlayerDatabase(){ std::vector&lt;BaseballPlayer*&gt;::iterator iter; for (iter=team.begin();iter!=team.end();iter++){ if (*iter) delete *iter; *iter=nullptr; } team.clear(); </code></pre> <p>}</p> <p>// a function that prints the baseball players onto the stdout and writes them into the given file</p> <pre><code>void PlayerDatabase::print_team(std::ofstream&amp; outputFile){ int totalHits=0, totalAtBats=0, totalEarnedRuns=0; float totalInningsPitched=0.0; std::vector&lt;BaseballPlayer*&gt;::iterator begin, end; begin=team.begin(); end=team.end(); int member=1; while (begin!=end){ std::cout&lt;&lt;"Member "&lt;&lt;member&lt;&lt;std::endl; (*begin)-&gt;print_player(outputFile); Pitcher* pPlayer= dynamic_cast&lt;Pitcher*&gt;(*begin); if (pPlayer){ totalEarnedRuns+=pPlayer-&gt;earnedRuns; totalInningsPitched+=pPlayer-&gt;inningsPitched; begin++; member++; } else{ Hitter* hPlayer= dynamic_cast&lt;Hitter*&gt;(*begin); totalHits+=hPlayer-&gt;hits; totalAtBats+=hPlayer-&gt;atBats; begin++; member++; } } if(totalAtBats==0||totalInningsPitched==0.0){ if(totalAtBats==0&amp;&amp;totalInningsPitched==0.0){ std::cout&lt;&lt;"Team Batting Average: "&lt;&lt;"n/a"&lt;&lt;std::endl; std::cout&lt;&lt;"Team ERA: "&lt;&lt;"n/a"&lt;&lt;std::endl; } else if (totalAtBats==0){ std::cout&lt;&lt;"Team Batting Average: "&lt;&lt;"n/a"&lt;&lt;std::endl; std::cout&lt;&lt;"Team ERA: "&lt;&lt;(totalEarnedRuns/totalInningsPitched*9)&lt;&lt;std::endl; } else { std::cout&lt;&lt;"Team Batting Average: "&lt;&lt;std::fixed&lt;&lt;std::setprecision(3)&lt;&lt;totalHits/(double)totalAtBats&lt;&lt;std::endl; std::cout&lt;&lt;"Team ERA: "&lt;&lt;"n/a"&lt;&lt;std::endl; } } else{ std::cout&lt;&lt;"Team Batting Average: "&lt;&lt;std::fixed&lt;&lt;std::setprecision(3)&lt;&lt;totalHits/(double)totalAtBats&lt;&lt;std::endl; std::cout&lt;&lt;"Team ERA: "&lt;&lt;(totalEarnedRuns/totalInningsPitched*9)&lt;&lt;std::endl; } </code></pre> <p>}</p> <p>// loads baseball players from an input file that is formatted</p> <pre><code>void PlayerDatabase::load_team(std::ifstream&amp; input){ int counter=1; while (!input.eof()){ char playerType; input.get(playerType); if (playerType==HITTER){ Hitter* hitter= new Hitter; hitter-&gt;load_player(input); std::cout&lt;&lt;"Loading member "&lt;&lt;counter&lt;&lt;std::endl; team.push_back(dynamic_cast&lt;BaseballPlayer*&gt;(hitter)); counter++; } else if (playerType==PITCHER){ Pitcher* pitcher= new Pitcher; pitcher-&gt;load_player(input); std::cout&lt;&lt;"Loading member "&lt;&lt;counter&lt;&lt;std::endl; team.push_back(dynamic_cast&lt;BaseballPlayer*&gt;(pitcher)); counter++; } } </code></pre> <p>}</p> <p>// a function to create a good team by eliminating some based on the goodHitter() and goodPitcher() functions</p> <pre><code>void PlayerDatabase::create_good_team(){ std::vector&lt;BaseballPlayer*&gt; goodTeam; std::vector&lt;BaseballPlayer*&gt;::iterator begin, end; begin=team.begin(); end=team.end(); while (begin!=end){ Pitcher* pPlayer= dynamic_cast&lt;Pitcher*&gt;(*begin); if (pPlayer){ if(pPlayer-&gt;goodPitcher()){ goodTeam.push_back(dynamic_cast&lt;BaseballPlayer*&gt;(pPlayer)); } else { if (*begin) delete *begin; *begin=nullptr; } begin++; } else{ Hitter* hPlayer= dynamic_cast&lt;Hitter*&gt;(*begin); if(hPlayer-&gt;goodHitter()){ goodTeam.push_back(dynamic_cast&lt;BaseballPlayer*&gt;(hPlayer)); } else { if (*begin) delete *begin; *begin=nullptr; } begin++; } } team.clear(); team=goodTeam; </code></pre> <p>}</p> <p>// creates a small team deleting the first four players in the vector</p> <pre><code>void PlayerDatabase::create_small_team(){ if(get_team_count()&gt;=REDUCE_BY){ std::vector&lt;BaseballPlayer*&gt;::iterator first, fifth; first= team.begin(); fifth=first+REDUCE_BY; while (first!=fifth){ if (*first) delete *first; *first=nullptr; first++; } team.erase(team.begin(),fifth); } else { std::vector&lt;BaseballPlayer*&gt;::iterator first,last; first= team.begin(); last=team.end(); while(first!=last){ if (*first) delete *first; *first=nullptr; first++; } team.clear(); } </code></pre> <p>} // number of team members</p> <pre><code>int PlayerDatabase::get_team_count(){ return team.size(); </code></pre> <p>}</p> <p>is there something wrong with this part?</p> <pre><code> std::vector&lt;BaseballPlayer*&gt;::iterator begin, end; begin=right.team.begin(); end=right.team.end(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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