I have a Seat Class and I'm trying to get my main file to access the Seat class and it's not working. Here is my code:

My seat class:

#include<iostream>
#include<iomanip>
#include<string>



class Seat{

public:
	char name;
	bool available;

	Seat(char name, bool available){
		this.name=name;
		this.available = available;
	}
	Seat(){
		name="A1";
		avaible = false;
	}

	void setName(char name){
		this.name=name;
	}

	char getName(){
		return name;
	}
}

And my main class

#include<iostream>
#include<iomanip>
#include<string>
#include<Seat>

using namespace std;

Seat A1 = new Seat("A1", true);

string input;

void main(){

	cout<<A1.getName() <<endl;
	
}

Recommended Answers

All 6 Replies

What is the filename of the first listing of code? It should probably be something like seat.h. Then you can change line 4 of the second listing to #include "seat.h" I understand what you were trying to do, but the < > signify to the compiler that you want to search a certain set of paths for the file (normally the includes folder, etc.). Here's a guide to the paths that the gcc uses in *nix http://www.mingw.org/wiki/IncludePathHOWTO. It will be different under Windows, as you can imagine.

Also, a side note, main always returns an int.

What's the actual error message(s) from the compiler?

I note that you're using new and feeding it Seat("A1", true), which seems a bit wrong as new has no such prototype; http://www.cplusplus.com/reference/std/new/operator%20new/

What happens if you abandon using new and just try this, within your actual main function?

Seat A1 = Seat("A1", true);

Also, I don't see how this could possibly compile, as your seat class makes use of a variable named

avaible

which doesn't exist; a mis-spelling, I suspect.

Also, the variable "name" is a single character, but you are trying to load it with "A1".

commented: All very true, too. +6

What's the actual error here?

I note that you're using new and feeding it Seat("A1", true)

What happens if you abandon using new and just try this, within your actual main function?

Seat A1 = Seat("A1", true);

Also, I don't see how this could possibly compile, as your seat class makes use of a variable named

avaible

which doesn't exist; a mis-spelling, I suspect.

The net result will be essentially the same, you'll just have an instance of a Seat instead of a pointer to a Seat object.

The problem is the #include statement. The OP should have used double-quotes instead of angle brackets around the file name. As jonsca said, it changes the compliler's behavior when searching for the requested file.

Lol, the eyes went from the header to the included headers of the main file. Good catch. There's also a "this" pointer that's being used improperly.

I think that object (once the pointer notation is added) should be reigned into main() for safekeeping.

Fbody, that was really more of a rhetorical "why not try this" question.

The problem is the #include statement.

There is more than one problem.

>>There is more than one problem.
Yes, there is. I do not disagree.

commented: This is a fair and balanced post. :) +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.