Newbie needs help with no match for `* std::string&' operator error

This is a discussion on Newbie needs help with no match for `* std::string&' operator error within the C++ Programming forums, part of the General Programming Boards category; I am receiving the following error when trying to use a pointer to an array that is defined using a ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    9

    Newbie needs help with no match for `* std::string&' operator error

    I am receiving the following error when trying to use a pointer to an array that is defined using a structure. If anyone can explain why I'm receiving this error I would really appreciate it.

    no match for `* std::string&' operator

    Here is the structure that the array is defined in

    Code:
    #include <iostream>
    #include <cstring>
    #include <cctype>
    #include <cstdlib>
    #include <string>
    
    using std::cout;
    using std::cin;
    using std::endl;
    using namespace std;
    
    const int IN_VEHICLE = 100;
    
    struct vehicles_in{
     string inVin;
     int inPassengerCount;
     string inLuxury;
     int inMpg;
     char inType;
    }new_vehicle [IN_VEHICLE];
    Here are the functions that are using a pointer to the new_vehicle array

    Code:
    void init_list()
    {
      int t;
    
      for (t=0; t<IN_VEHICLE; t++)*new_vehicle[t].inVin = '\0';
    }
    
    void enterNewVehicle()
    {
      int i;
    
      for (i=0;i<IN_VEHICLE; i++)
        if (!*new_vehicle[i].inVin) break;
    
      if (i==IN_VEHICLE){
      cout << "This list is full.\n";
      return;
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Too much indirection?
    Code:
    void init_list()
    {
       int t;
    
       for ( t = 0; t < IN_VEHICLE; t++ )
       {
          new_vehicle[t].inVin = '\0';
       }
    }
    (No *.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    ZuK
    ZuK is online now
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    new_vehicle[t].inVin is a std:string it is initialized to "" in its constructor. -> you don't need the function init_list().
    If you want to use it later on to reset the string you could try this way
    Code:
    void init_list() {
      int t;
      for (t=0; t<IN_VEHICLE; t++) 
         new_vehicle[t].inVin = "";    
    }
    new_vehicle is an array of vehicles_in's so you must not dereference it

    Code:
      for (i=0;i<IN_VEHICLE; i++)
        if ( ! new_vehicle[i].inVin.length() ) break;
    Kurt

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    Thanks, this helped.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21