Thread: Newbie - Could not convert to bool error

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

    Newbie - Could not convert to bool error

    I keep receiving the following compiling error when trying to print a data structure from within an array:

    could not convert 'new_vehicle[t].vehicles_in::inVin' to 'bool'

    If anyone can offer any insight about this error, I'd really appreciate it!

    Here is the code that defines the data structure within the array:

    Code:
    #include <iostream>
    #include <cstring>
    #include <cctype>
    #include <cstdlib>
    #include <string>
    #include "Vehicle.cpp"
    #include "maxarray.h"
    
    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];
    This is the code where I am calling the function to print the data structure:

    Code:
    void listVehicles()
    {
      int in;
    
      for (in=0; in<IN_VEHICLE; in++)
      printVehicle();
    }
    And here is the code for the function that is printing the data within the array.

    Code:
    void printVehicle()
    {
      int t;
    
      for (t=0;t<IN_VEHICLE;t++)
      {
      if (new_vehicle[t].inVin)
      {
      cout << new_vehicle[t].inVin;
      cout <<  new_vehicle[t].inPassengerCount;
      cout << new_vehicle[t].inLuxury;
      cout <<  new_vehicle[t].inMpg;
      cout << new_vehicle[t].inType;
    
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Code:
    if (new_vehicle[t].inVin)
    What exactly does this mean?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    9
    This is supposed to be checking to see if something has been entered into inVin to see if there is something to print out; however, this statement is similar to an example I had in a book so I'm not sure if I did it right.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I presume that's talking about the if (new_vehicle[t].inVin) statement. Try changing it to

    if (new_vehicle[t].inVin!=0)

    if it's a number.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This is supposed to be checking to see if something has been entered into inVin to see if there is something to print out; however, this statement is similar to an example I had in a book so I'm not sure if I did it right.
    Then you should write:
    Code:
    if (!new_vehicle[t].inVin.empty())
    if it's a number.
    It's a string.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    41
    or change struct to char * inVin;

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    you also don't have enough closing braces.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by Shal
    or change struct to char * inVin;
    Very bad idea without understanding all the implications. (And a bad idea even then.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    41
    Y is it bad to use char *?

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    1. It's a pointer to char and therefore shouldn't be used to hold an array of char.
    2. Yet you can make a pointer to a char array and it works as long as it's in scope.
    3. The confusion that arises when you want to return a string but you have to return char * instead because arrays decay into pointers when calling functions.
    ... 73. The array might not be big enough.
    866. To get an array big enough you have to do a lot of footwork to dynamically allocate memory
    1234. ...and reallocating if that isn't big enough.

    The List Continues...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM