Sign in to follow this  
mattchew008

*problem "" error...help

Recommended Posts

Hi, I am kind of new with C++ and I'm working on an assignment however I continue getting the same error: inary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char> ,class std::allocator<char> >' (or there is no acceptable conversion) I have searched google for this problem but was unable to find a solution. I have included the iostream.h, string and added namespace std, but it still does not work. If someone could look at my code and help me with what the problem might be it would be greatly appreciated. This is the Code
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include <iostream.h>
using namespace std;

class main  
{

};

class Junkyard  
{
private:
	int NumBusDoors; 
	int NumTruckDoors; 
	int NumCarDoors; 
	int NumWheels; 

public:
	Junkyard () {NumBusDoors = 0; NumTruckDoors = 0; NumCarDoors; NumWheels;}

void Junkyard::AddBusDoors(int numDoors) {
	NumBusDoors = NumBusDoors + numDoors;
}

void JunkyardAddTruckDoors(int numDoors) {
	NumTruckDoors = NumTruckDoors + numDoors;
}

void JunkyardAddCarDoors(int numDoors) {
	NumCarDoors = NumCarDoors + numDoors;
}

void JunkyardAddWheels(int numWheels) {
	NumWheels = NumWheels + numWheels;
}

void JunkyardAdvertise() { //print the content of the junkyard to the screen in order to show the stocks this junkyard has
	cout << "Bus Doors: " << NumBusDoors << "\nTruck Doors: " << NumTruckDoors << "\nCar Doors: " << NumCarDoors << "\nWheels: " << NumWheels;
}

virtual ~Junkyard();

};


class Location  
{
public:
	int x,y;
	Location();
	virtual ~Location();

};



class Road 
{
public:
	string RoadName; 
	Location EntryEndPoint; 
	Location ExitEndPoint; 
	enum Direction {East, South}Dir ;

	Road(string Rname, Location EntryEP, Location ExitEP, Direction aDir)
	{
		RoadName = Rname;
		EntryEndPoint = EntryEP;
		ExitEndPoint = ExitEP;
		Direction Dir= aDir;
	};

	virtual ~Road();

};

class Vehicle
{
protected:
	string Name ;
	int Speed ;
	int LoopsPerM ;
	int CurLoopCount ;
	int NumWheels ;
	int NumDoors ;
	Location Position ;
	Road* RoadPtr ;
	
	Vehicle () {
		Speed = 0;
		LoopsPerM = 0;
		CurLoopCount = 0;
		NumWheels = 0;
		NumDoors = 0;
		RoadPtr = '\0';
	}; //initializes all attributes to zero

	Vehicle (string name, int speed, Road* rdPtr) { 
		LoopsPerM = (int) (3.6/Speed*100); 
		CurLoopCount = 0;
	}
	void move (Road*, Road*);

	virtual ~Vehicle() {
		cout << "vehicle " << Name << " is destroyed"; // this is line 107!
	};
	virtual JunkIt(Junkyard &jy); 
};

void Vehicle::move (Road* R1, Road* R2) { 
               CurLoopCount++;

               if (CurLoopCount == LoopsPerM) {

                 if (RoadPtr->Dir == 0) { 

                    Position.x++;

                    if (Position.x == RoadPtr->ExitEndPoint.x) {

                       RoadPtr = R2;

                       Position.x = 500;

                       Position.y = 1000;
                    }
                  }

                 else { // South

                    Position.y--; 

                    if (Position.y == RoadPtr->ExitEndPoint.y) {

                       RoadPtr = R1;

                       Position.x = 0;

                       Position.y = 500;

                    }
                 }
			  }
};

class Car: public Vehicle{
	bool MoonRoof;
	Car (string name, int speed, bool MoonRoof, Road* rdPtr ): Vehicle(name, speed, rdPtr) {NumWheels = 4; NumDoors = 4} ;
	void JunkIt(Junkyard &jy, int);//update jy’s NumCarDoors and NumWheels using the correspongin public mehtod } 
	~Car() { cout << "Car " << Name << " is destroyed";} ;
};
void Car::JunkIt (Junkyard &jy, int x = 0) {
	jy.JunkyardAddCarDoors(NumDoors);
	jy.JunkyardAddWheels(NumWheels);
};

class Bus: public Vehicle{
	enum style {Single, DoubleStories, Attached} BusType ;
	Bus (string name, int speed, enum style bType, Road* rdPtr): Vehicle (name, speed, rdPtr) {NumWheels = 6; NumDoors = 3} ;
	void JunkIt(Junkyard &jy, int); //update jy’s NumBusDoors and NumWheels using the correspongin public mehtod } 
	~Bus() { cout << "Bus " << Name << " is destroyed";} ;
};
void Bus::JunkIt (Junkyard &jy, int x = 0) {
	jy.AddBusDoors(NumDoors);
	jy.JunkyardAddWheels(NumWheels);
};

class Truck: public Vehicle {
	Truck(string name, int speed, Road* rdPtr) : Vehicle(name, speed, rdPtr) {NumWheels = 6; NumDoors = 2} ;
	void JunkIt(Junkyard &jy, int);//update jy’s NumTruckDoors and NumWheels using the correspongin public mehtod} 
	~Truck() { cout << "Truck " << Name << " is destroyed";} ;
};
void Truck::JunkIt (Junkyard &jy, int x = 0) {
	jy.JunkyardAddTruckDoors(NumDoors);
	jy.JunkyardAddWheels(NumWheels);
};

class Motorcycle: public Vehicle { 
	Motorcycle (string name, int speed, Road* rdPtr) : Vehicle(name, speed, rdPtr) {} ;
	void JunkIt(Junkyard &jy, int){}; //nothing to be junked } 
	~Motorcycle() { cout << "Motorcycle " << Name << " is destroyed";} ;
};


this is the error ompiling... Assignment2test.cpp D:\Documents and Settings\Mattchew008\My Documents\SCHOOL\1-2004 FALL\test\Assignment2test.cpp(107) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char> ,class std::allocator<char> >' (or there is no acceptable conversion) Error executing cl.exe. Assignment2test.obj - 1 error(s), 0 warning(s) ---------------------------------------------------- I'm seriously stuck and I have no idea what the problem might be. Thank you in advance for your help Matt [edit : added source tags -SiCrane] [Edited by - SiCrane on November 7, 2004 10:56:56 PM]

Share this post


Link to post
Share on other sites
My first guess is that your problem is mixing old style and new style C++ headers. Try switching from using <iostream.h> to <iostream>, and see if that helps.

Share this post


Link to post
Share on other sites
Thank you!
It has gotten rid of that problem however now I have a complier error


----------

Compiling...
Assignment2test.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Assignment2test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Assignment2test.exe - 2 error(s), 0 warning(s)

-----------

does anyone know what this problem might be?

Thank you


Matt

Share this post


Link to post
Share on other sites
That's actually a linker error, not a compiler error. With a quick glance at your code, and I don't see a main() function for your program. You need to add one if you want your program to do anything.

Possibly, since this looks to be a homework problem, your teacher has supplied another source file you need to link against. In that case, you need to add it to your project.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this