|
I am writing some fairly simple code for a uni assignment and I have this error come up in a couple of instances "Declaration terminated incorrectly", I have checked the code over many times and just can't seem to work out the problem. The error occurs when I compile barDrv.cpp, and the error is in CustomerOrder.h on line 10. Here the code for the two files:
barDrv.cpp
//File: barDrv.cpp
//Test harness for assignment
#include <iostream>
#include "CustomerOrder.h"
#include "Bar.h"
static const int MAX_ITEMS_IN_CUSTOMER_ORDER = 15;
static const int MAX_ITEMS_IN_BAR_MENU = 40;
int main()
{
char choice;
int nextMenu = 1;
Bar theBar(MAX_ITEMS_IN_BAR_MENU);
CustomerOrder theCustomerOrder(MAX_ITEMS_IN_CUSTOMER_ORDER);
theBar.maintainStock();
do
{
theBar.printBar();
cin>>choice;
switch(choice)
{
case 'Q':
cout<<"Thankyou for using Tunerica Corporations software!";
nextMenu = 0;
case 'I':
int number;
theBar.printInclude();
cin>>number;
theCustomerOrder.includeItem(number, theBar);
case 'X':
int number2;
theCustomerOrder.printExclude();
cin>>number2;
theCustomerOrder.excludeItem(number2);
case 'P':
char whatToDo;
theCustomerOrder.printInvoice();
cin>>whatToDo;
if (whatToDo == 'Y')
theCustomerOrder.~CustomerOrder();
else
nextMenu = 0;
}
}while(nextMenu!=0);
return 0;
}
CustomerOrder.h
//File CustomerOrder.h
//Interface for the CustomerOrder class
#ifndef CUSTOMERORDER_H
#define CUSTOMERORDER_H
#include <string>
#include "Bar.h"
using namespace std; <<<<<-Where the error apparently is
class CustomerOrder
{
public:
CustomerOrder(int maxItems);
~CustomerOrder();
void includeItem(int choice, Bar aBar);
void excludeItem(int choice);
void printExclude();
void printInvoice();
private:
int numInInvoice;
int numItemsInvoice;
double calcTotal();
Item * * invoice;
};
#endif
Any help or suggestions would be greatly appreciated.
Thanks in advance.
|
|
|
|
|
1) Start by moving "using namespace std;" to the source file instead of the header file, because the header file is not the file that is using it (amongst other reasons).
2) Except that the syntax is C++, it looks like you think the case statement works that same as the simular constuct in VB. You must place a "break;" at the end of each case and before the next case.
3) This "theCustomerOrder.~CustomerOrder();" is a call to the destuctor of "theCustomerOrder", do not do this (EVER!). I've never seen anyone do this before!!!
Once you fix this problems, you may see your error disapear!
Good Luck!
INTP
|
|
|
|
|
Thanks for the reply, ended up figuring out what the problem was, I left the semi colon from the end of the Bar class.
|
|
|
|
|
Hi. I cant seem to find anything simple that will allow me to display a JGP (or Bitmap) on a dialog window. All I want to do is display 1 image on a dialog, thats it. If anybody has some code they would like to share to do this, that would be great!! I'm using MS VC++ (MFC exe).
Thanks alot!!
Boots
|
|
|
|
|
search for cpicture class here on CP, it does just that
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
I need to translate this code from Ansi C to C++, it copies everything from the file (except EOF or /n) to the string temp
<br />
string temp;<br />
<br />
FILE *arch;<br />
char c;<br />
<br />
arch=fopen(s,"r");
<br />
while (!feof(arch))<br />
{<br />
c=fgetc(arch);<br />
if ((c!=EOF) && (c!='\n'))<br />
temp=temp+c;<br />
}<br />
fclose (arch);<br />
i know the first line may be:
ifstream arch (s);
thanks
hope you can help me!!
|
|
|
|
|
#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cin;
using std::string;
using std::ifstream;
int _tmain(int argc, _TCHAR* argv[])
{
// I used a hard coded path
ifstream arc("c:\\ls.txt");
string s;
string file;
// check if the file is ended OR bad
while(!arc.eof() && !arc.bad())
{
// getline will get up to but not including the line break, which is what you were after.
getline(arc, s);
// each line is then added to the final result.
file += s;
}
// show the result
std::cout << file;
// this last bit is just to stop the window closing
std::cin >> s;
return 0;
}
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Apologies to Christian, but you can keep it just how it is and just change the file extension to .cpp.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
i hope you're kidding.....C != C++
|
|
|
|
|
I'm sure Joe was joking, but he does make a valid point, right?
C++ can be thought of as a superset of C, and although the original code does not make use of C++ specifics, it still is valid C++ code.
Can anyone verify or correct me in this? C++ is certainly not C, but C++ is backwardly compatible (or should be), to the standard ANSI C standard?
I Dream of Absolute Zero
|
|
|
|
|
no, that right...
except some particuliar cases, C++ IS a superset of C and so C code is understood and compiled by C++ compilers
TOXCCT >>> GEII power
|
|
|
|
|
fopen n stuff are CRT funtions they are available in c++ too.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Please refer to Appendix B in the book "The C++ Programming Language, 3rd" by Stroustrup for...
B.2.2 C Code That Is Not C++, (Page 816)
B.2.4 C++ Code That is Not C. (Page 819)
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote:
B.2.2 C Code That Is Not C++, (Page 816)
B.2.4 C++ Code That is Not C. (Page 819)
No snippets
Awhh go on.. give us a clue what it says (briefly).
I Dream of Absolute Zero
|
|
|
|
|
RChin wrote:
No snippets
It's *A LOT* ~~~
Now you have some choices:
1) Go to a library to get that book,
2) Buy one (special edition) from a book store,
3) Download the whole book in pdf at HERE[^].
Don't tell Stroustrup that I posted his book in pdf here; otherwise he would probably spank me.
Maxwell Chen
|
|
|
|
|
I wasn't joking at all. Just because you need to move something from C to C++ doesn't mean you have to change everything to use only those things specific to C++. The code is perfectly valid C++ code as written. Why fix something that isn't broken? (better yet, why make something more bloated just so for appearances?)
(I've actually seen someone take the equivilant of:
int values[MAX_VALUES];
and turn it into:
vector<int> values;<br />
values.resize(MAX_VALUES);
)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hey,
Say e.g. you are using a SetTimer() to get frames from a video device.
I find It takes up all the CPU. How do people cope with this? I really want to get frames
as fats as possible but I also dont want the GUI or display to suffer. What do people do ?
Do they put a wait in the SetTimer call?
Regards,
|
|
|
|
|
try creating a seperate thread and wait there for as much time and try to grab a frame,
might work
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
They usualy use DirectX (DirectDraw) or OpenGL. If you must use SetTimer then only use it to invalidate the portion of the client area that needs changing OR use it to post a user defined message that instructs your program to load the next frame and let the function that handles that message invalidate the area. You should spend as little time as possible in the function used to handle the timer message (OnTimer). You should also look into using a thread to load the images in the backgound. While you're surffing look for code that is used to display .flc, .avi and .mpeg files, they may provide the answers you are looking for.
INTP
|
|
|
|
|
Hi
I am opening the com port for a printer device and it opens it even if the printer is not connected. More over it sends the data also to com port even printer is not there.
Can any body help me how can i detect the device is connected or throw an error if device is not connected or can detect something on the data is not receiving to the device?
Thanks
Shailesh
|
|
|
|
|
ports will connect regardless of the device connected or not, try to send some data and then wait for the signal from the printer, if no signal then raise error
if you just want to control the printer why not use the printer api
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
i am trying to perform some functions on a floppy. i created a handle for that floppy and tried to read the bootsector using ReadFile and WriteFile.
i would like to
Perform a directory listing of the current directory on the floppy
Change directories on the floppy
Create directories on the floppy
Delete directories on the floppy
please show examples if possible or give link to any helpfull website on accessing a floppy disk
|
|
|
|
|
Assuming you have a drive letter for the floppy, the following functions will work.
FindFirstFile / FindNextFile
SetCurrentDirectory
CreateDirectory
DeleteFile , or SHFileOperation
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
I have run into some problems while trying to write a scripting language in VC++ 7. I want it to all be in an edit box. For example, if the user types this in the edit box:
String MyString = "Hello";
if (MyString == "Hello")
sendkeys(Hello);
else
MoveMouse(160,480);
end;
Quite a pointless program, but I am having a hard time handling it with C++. How do I handle the boolean logic, and how would I get both of the parameters of the MouseMove function. I would like the program to execute from the top to the bottom. Anyone have any idea how to do this? I just need the basic idea of how to do it. Any help would be appreciated
-Dev578
|
|
|
|
|
writing an interpreter is a huge task. if you don't know where to begin, you're much better off using an interpreter that's already written.
there are free interpreters for many languages out there, including things like VBScript, Tcl, Lua, Python, Ruby, etc.. try Google.
Cleek | Losinger Designs | ClickPic | ThumbNailer
|
|
|
|