DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Visual C++ Help please (Vector<>)  (Read 6,508 times)

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
Visual C++ Help please (Vector<>)
« on: February 20, 2009, 08:56 AM »
OK I have written this small program that helps me learn Chinese and it works in C++ but I want to have a GUI for it current no GUI, So I am transferring it over to Visual C++ making changes as I need too. I have come to a problem with my Vectors.

Error
Code: (cpp)
errorC2923:'std::vector' : 'words' is not a vaild template type argument for parameter '_Ty'

the error is happening here.

Code: (cpp)
// Chinese learning.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include "words.h"
#include <vector>
#include <string>
#include <fstream>

using namespace Chineselearning;
	//functions
	void split(std::string, std::vector<std::string>&);
	int checkword(std::vector<words>&, std::string);
	void getword(std::vector<words>&, std::string);
	void getfile(std::vector<words>&, std::vector<words>&);
	//void outfile(std::vector<words>&, std::vector<words>&);
	void print(std::vector<words>&);
	int getrand(int);
	void display(std::vector<words>&);

	// TODO: Add extra initialization here
	std::vector<words> vecWords;
	std::vector<words> vecWordsTemp;
	std::vector<std::string> words;
    int input = 0;
    int index = 0;
	std::string lineIn;
	
	//start
	
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());

	getfile(vecWords, vecWordsTemp);
	return 0;
}
//ERROR happening on this line std::vector<words>& vecTemp
int checkword(std::vector<words>& vecTemp, std::string word)
{
 int index = -1;
 if(vecTemp.size() != 0)
 {
  for(std::vector<int>::size_type ix = 0; ix != vecTemp.size(); ++ix)
  {
   if(vecTemp[ix].getNewWord() == word)
   {
   return ix;
   }//end if                               
  }//end forloop 
 }//end if
 return index;     
}//end checkword

words is a class not a template.

I am also getting some other error message that I have not looked at yet.

As I am learning Visual C++ please do not change the code and send it back to me. I would like to know what I am doing wrong and How to fix it.

Thanks.
« Last Edit: February 20, 2009, 12:16 PM by Davidtheo »

Eóin

  • O'Callaghan
  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
Re: Visual C++ Help please (Vector<>)
« Reply #1 on: February 20, 2009, 10:07 AM »
At line 24 you have defined a variable std::vector<std::string> words so from then on the identifer words doesn't refer to your class.

Rename that variable and all is well :Thmbsup:
Interviewer: Is there anything you don't like?
Bjarne Stroustrup: Marketing hype as a substitute for technical argument. Thoughtless adherence to dogma. Pride in ignorance.

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
Re: Visual C++ Help please (Vector<>)
« Reply #2 on: February 20, 2009, 12:20 PM »
Hi Eoin,

Thanks for your help  :Thmbsup:

Original address: https://www.donationcoder.com/forum/index.php?topic=17118.0