Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 02:18:41 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Visual C++ Help please (Vector<>)  (Read 2721 times)

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Visual C++ Help please (Vector<>)
« on: February 20, 2009, 02:56:55 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: C++ [Select]
  1. errorC2923:'std::vector' : 'words' is not a vaild template type argument for parameter '_Ty'


the error is happening here.

Code: C++ [Select]
  1. // Chinese learning.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include "Form1.h"
  5. #include "words.h"
  6. #include <vector>
  7. #include <string>
  8. #include <fstream>
  9.  
  10. using namespace Chineselearning;
  11.         //functions
  12.         void split(std::string, std::vector<std::string>&);
  13.         int checkword(std::vector<words>&, std::string);
  14.         void getword(std::vector<words>&, std::string);
  15.         void getfile(std::vector<words>&, std::vector<words>&);
  16.         //void outfile(std::vector<words>&, std::vector<words>&);
  17.         void print(std::vector<words>&);
  18.         int getrand(int);
  19.         void display(std::vector<words>&);
  20.  
  21.         // TODO: Add extra initialization here
  22.         std::vector<words> vecWords;
  23.         std::vector<words> vecWordsTemp;
  24.         std::vector<std::string> words;
  25.     int input = 0;
  26.     int index = 0;
  27.         std::string lineIn;
  28.        
  29.         //start
  30.        
  31. [STAThreadAttribute]
  32. int main(array<System::String ^> ^args)
  33. {
  34.         // Enabling Windows XP visual effects before any controls are created
  35.         Application::EnableVisualStyles();
  36.         Application::SetCompatibleTextRenderingDefault(false);
  37.  
  38.         // Create the main window and run it
  39.         Application::Run(gcnew Form1());
  40.  
  41.         getfile(vecWords, vecWordsTemp);
  42.         return 0;
  43. }
  44. //ERROR happening on this line std::vector<words>& vecTemp
  45. int checkword(std::vector<words>& vecTemp, std::string word)
  46. {
  47.  int index = -1;
  48.  if(vecTemp.size() != 0)
  49.  {
  50.   for(std::vector<int>::size_type ix = 0; ix != vecTemp.size(); ++ix)
  51.   {
  52.    if(vecTemp[ix].getNewWord() == word)
  53.    {
  54.    return ix;
  55.    }//end if                              
  56.   }//end forloop
  57.  }//end if
  58.  return index;    
  59. }//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, 06:16:24 AM by Davidtheo »

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Visual C++ Help please (Vector<>)
« Reply #1 on: February 20, 2009, 04:07:39 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:

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: Visual C++ Help please (Vector<>)
« Reply #2 on: February 20, 2009, 06:20:13 AM »
Hi Eoin,

Thanks for your help  :Thmbsup: