|
in Flight.h i have this prototype :
bool reserveSeat(Passenger psngr, bool smoker);
and i have to do the implementation for it , i try to do it but i got an error :
"
error message :
task b\flight.cpp(15): error C2228: left of '.setPassportNumber' must have class/struct/union
1>type is ''unknown-type''
1> b\flight.cpp(16): error C2065: 'passenger' : undeclared identifier
1>b\flight.cpp(16): error C2228: left of '.setContactNumber' must have class/struct/union
1>type is ''unknown-type''
1> b\flight.cpp(17): error C2228: left of '.smokerSeat' must have class/struct/union
and here is my try
bool Flight::reserveSeat(Passenger psngr, bool smoker)
{
Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
reservations.smokerSeat=smoker;
}
note that Flight have an object of Reservation and here's the Reservation constuctor :
Reservation.cpp
Reservation::Reservation(Passenger& psngr, bool smoke)
{
passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
smokerSeat=smoke;
}
and here's the whole Flight Header
#include "reservation.h"
#include "okReservation.h"
#include "waitReservation.h"
class Flight{
private:
int waitingListMax;
int seats;
int seatsCount;
Reservation** reservations;
public:
Flight(int capacity, int waitingMax);
bool reserveSeat(Passenger psngr, bool smoker);
void cancelReservation(string resNum);
okReservation confirmReservation(waitReservation* res);
void printWaitingList();
void printReservationList();
};
|
|
|
|
|
alaaan73 wrote: Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
as far as i can tell, you have not declared any variables named "Passenger" or "passenger".
reservations.smokerSeat=smoker;
you have declared reservations as a pointer to a pointer to a Reservation.
Reservation** reservations;
so you can't use "reservations.smokerSeat". you would have to declare it as:
Reservation reservations;
etc..
|
|
|
|
|
You have:
bool Flight::reserveSeat(Passenger psngr, bool smoker)
{
Passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
reservations.smokerSeat=smoker;
}
which makes little sense. you are using both Passenger (with upper case P), and passenger (with lower case p) to refer to something. But what, why would you try to set the value of an item in an object from the value taken from that object? Similarly the statement
reservations.smokerSeat=smoker;
make little sense as reservations is a pointer to a pointer (of something). I think you are a little confused about your classes and how they connect to each other.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You can call a class method either by using the '. ' operator on an instance of that class, e. g.
psngr.SetPassengerName("SomeName");
Or by using the '::' operator on the class, if it is a static method, e. g.:
Passenger::SetPassengerName("SomeName");
I don't think either makes sense in this case however.
Your mistakes have already been pointed out, but from the information you gave us it's hard to derive what is actually needed to fix them. Looking at the declaration of class Flight , I suspect that reservations is supposed to be a list of, well, reservations. The prototype of cancelReservation(string resNum) indicates that you are supposed to use a string representing the reservation number as a key for retrieving a specific reservation. So your reservations may in fact be organized as a sorted tree - but that is something you have to find out for yourself.
In any case, the method reserveSeat() should create a new object of type Reservation and add it to that list. Probably you should apply these method calls on that new object in order to properly initialize it. The declaration of class Reservation should shed more light on this.
|
|
|
|
|
Hi,
I have used DirectShow to capture a video stream in C++/MFC. Now I want to increase the quality of the captured video, I want to capture HD video using DirectsShow/DirectX.
Is it possible to capture HD video using DirectX/DirectShow in C++/MFC/VC++.?
Any help will be appreciated.
Thanx in Advance.
Regards,
Mbatra
|
|
|
|
|
Have you done it? Please help me
|
|
|
|
|
|
In InitInstace after OnFileNew() called, its was found m_phWnd is null. OnFileNew() is default implementation of mfc.
Please help me out.
|
|
|
|
|
You should provide more information to get help. Use the 'Edit' link below your post to do this (e.g. add a short code snippet).
What is the class for m_phWnd (there is no CWinApp member with this name?
|
|
|
|
|
Actually I had wrongly mention the member name, it is m_pMainWnd.
I am sorry, I cannot provide the code snippet.
|
|
|
|
|
m_pMainWnd is not set by MFC. It is provided to be used in your code. Common usage is to assign the address of your main frame window (or the main dialog with dialog based applications) upon creation in InitInstance() :
CMyApp::InitInstance()
{
...
CMainFrame * pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = static_cast<CWnd*>(pMainFrame);
...
}
Purpose is to have access to your main frame class from all modules of your app:
CMainFrame * pMainFrame = static_cast<CMainFrame*>(AfxGetApp()->m_pMainWnd);
|
|
|
|
|
ok so i am given the goal to read the disk file and separate each line into three fields of text, idnum, Name, absences and either store the data into three parallel arrays, or a linked list of objects the professor is going to give us a alternate file of student info. i was going to do a linked list but i am unsure of how to make it attached to a disk file. And how to implement it as we only spent one class on linked lists. I will admit i dont know much about linked lists. i know the basic formatting of them and ive read everything that my book covers but the information im seeking either im not comprehending or is unavailable in it. Being the goal of this project i figured a linked list would be the best course of route
all info and input is greatly appreciated here is what i have so far for the program as i said linked lists are not my strongest area
ramdom is the name of the text file btw
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
{
struct Student;
int idnum;
student *next;
}
int idnum[10000000];
char name[10000000];
double absence[100000000];
ifstream infile("random.txt");
int search_idnum;
char random[50];
ofstream out_stream;
cin.getline(random, 50);
out_stream.open(random);
if (infile.fail())
{
cout << " unable to open the file" << endl;
return 1; }
else
{
cout << "Please enter the student id number: ";
cin >> search_idnum;
random >> idnum;
if (int idnum == int search_num)
{ random >> idnum >> name >> idnum;
cout << "For the idnum " << idnum << " the \n"
<< "last name is: \n" << name << "and the "
<< "absences is: \n" << absences;
}
else
{ {
cout << "I could not find the student number.";
system ("pause");
}
return 0;
}
here is the info
Quote:
4215534 Austin 3
5551298 Bailey 3
6224649 Balovich 4
6502286 Bates 4
8448936 Bettencourt 2
2883903 Blackburn 9
6752376 Boucher 1
3564698 Brown 2
6373150 Duncan 2
6375372 Estrada 1
modified 18-Dec-12 1:14am.
|
|
|
|
|
You certainly do not need to start with 10,000,000 element arrays reserved in memory. You also seem confused about how to handle data streams. You have opened an input stream and then an output stream, but you never use either of them. You are also trying to use a character array as a stream.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I know if I have a class like that
class A
{
shared_ptr<SomeType> data;
}
I don't need to declare a destructor, as the compiler will automatically write one for me that take care of everything.
But what if I have a resource without a destructor, such as a handle.
I need to implement a destructor
class A
{
shared_ptr<SomeType> data;
HANDLE wndobj;
~A() {
CloseHandle(wndobj);
}
}
Do I need to handle all variable? or only those without destructor (i.e. wndobj)?
I.e. what of data?
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Good question, if your class allocated the pointer, but shared it with other classes, then you will need to reference count it and olny delete the allocation when the last reference is removed.
==============================
Nothing to say.
|
|
|
|
|
it's a shared_ptr! the reset method is here for that, it decrease ref count.
so, if I get you right, when I declare my own explicit destructor I do need to call all the destructor of my properties? but I didn't use new... (as in ComPtr<t> that I get through a query) mmm .. I guess I set those to null..
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Super Lloyd wrote: but I didn't use new...
That has nothing to do with it.
The use of 'new' is specific to a certain kind of finite resource (memory).
Your class on the other hand must manage ALL of the resources that it owns. So it must clean it up.
|
|
|
|
|
I wrote a little test program to answer all my questions!! :P
To answer the one on this page, no need to call .reset()!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I think that what Eric meant above was that if you share the resource handle through the shared_ptr then you should not CloseHandle prematurely, when others still are using it. Thus you need to examine the ref count before CloseHandle, or else you will have invalid objects.
Life is too shor
|
|
|
|
|
Errr, we're talking about the destructor and said shared_ptr object is about to be destroyed - it doesn't have to be reset! Would be a dumb kind of smart pointer if you still have to tell it to decrease the reference before destroying it...
|
|
|
|
|
A little test program clarified everything! ^^
All non pointer member's destructor get called at all time, whatever else might be...
I was just not sure initially! ^^
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Yes, I was talking generally and as you say the shared_ptr class does this for you so no need to worry about it.
As for things like handles, in your example, it is best to call a close on them before your class destructor is called, ie, do your tidy up as early as you can.
==============================
Nothing to say.
|
|
|
|
|
The destructor will be called on data, so there's no need to call reset.
Steve
|
|
|
|
|
Thanks!
Indeed I though of writing a test program and found that out too!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Helo i want to implement fuzzy logic code in C++ and i am new in it can any one help me plz i need urgent help
|
|
|
|