|
I an having trouble I have a document that has 3 sections,the full page is supposed to have a graphic overlayed on it.
If I try copying the graphic onto the page using srcand all I see is the graphic.
The other output is all from richedit controls, I have had no luck getting the richedit control to print into an in memory bitmap (so could do the overlay before printing). (I'll be posting another question about richedit).
The test printer type is adobe pdf writer.
|
|
|
|
|
Hi All,
I ve a doubt. Is it necessary to override copy constructor inside a sigleton class? if Yes, why so?
I c'd nt find a satisfactory answer in net, so thought to put it here.
Thank u all.
|
|
|
|
|
A singleton class usually also controls its creation.
This is normally done using a static method so that clients can call the static method to get hold of the one and only object instance of the class.
To prevent clients from directly creating objects of the class, we make the constructors private.
When the default constructor is private, clients will not be able to create an instance of the class as follows -
CMySingletonClass Obj;
And when the copy constructor is private clients cannot instantiate the class as follows -
CMySingletonClass AnotherObj(Obj);
|
|
|
|
|
Thank u superman for the reply. But my doubt is if i have a singletonclass, assume CMySingleTon, and inside the class i've static CMySingleton& GetInstance() methode whice is returning the static CMySingleTon obj.
If i need the object, I've to call like CMySingleton::GetInstance();, and i cannt create an object outside class.
My doubt is that when
<br />
CMySingletonClass AnotherObj(Obj);
will be called. And is it possible.
Thank u all.
|
|
|
|
|
This is where it would be called -
CMySingleton& obj = CMySingleton::GetInstance();
CMySingleton AnotherObj(obj);
|
|
|
|
|
If you don't provide a copy constructor and write something that the compiler implements by making a copy of your object, the compiler can and will provide a default one and silently use it. Then you no longer have a singleton.
Declare a private copy constructor and do not implement it. Now the compiler will not provide its own. In addition, if code outside the class tries to create a copy, you get a compile time error for trying to access a private function. Finally, if somehow code inside the class tries to make a copy, you get a link time error since the implementation is missing. What you don't get is an executable that is making copies of your "singleton" without you realizing it.
|
|
|
|
|
Hello all, I just wanted to post here because I can not figure this out. I run the program in debugging mode which does not help at all for this. Maybe I just dont know how to use the debugger correctly yet.
The program compiles without any errors, but after you enter your name the program exits. I dont understand it. I looked over the code time and time again and cant figure it out. So here is the very short code listed below. I appreciate any feedback on the obvious error with my program.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double iovertime_hours=0;
double iovertime_pay=0;
double iovertime_extra=0;
int cname ;
int ihours ;
int iwage ;
cout << "\n\nEnter the employee name = " ;
cin >> cname ;
cout << "Enter the hours worked = ";
cin >> ihours ;
cout << "Enter his or her hourly wage = ";
cin >> iwage ;
if (ihours > 40)
{
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
}
else (ihours < 40);
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
}
return 0;
}
</pre>
|
|
|
|
|
look at
else (ihours < 40);
{
what do you think that semi-colon is doing ? if you remove it, which you should, you'll get a compile error with that statement as it is (so you have another change to make) ... is that enough of a clue ?
'g'
|
|
|
|
|
G,
First off thanks for the response.
I should have removed that semi-colon before posting here. I had it removed and added it right after I copied the entire source and pasted here.
Without the semi-colon I am still stuck. The compile error I get is:
overtime.cpp In function `int main()':
43 overtime.cpp expected `;' before '{' token
So that is why I put the semi-colon after the else selection statement. I am still confused on how to correct the error that I obviously do not see. If you could provide another hint, I would be able to figure it out. Just need a point into the right direction.
Thank you again.
V/R
Rob
|
|
|
|
|
ok, so, think about the syntax of an if then else statement
your first test is
if (hours > 40)
you have two options at that error - (a) there can be no other conditions, in which case you only need the else, or (b) you want to test for maybe (hours < 20) for example ...
Im presuming the first - so try this
else
see what Ive done - Ive turned your (wrong) statement into a comment, ie, if hours and not > 40 they must then fall into the the 'everything else' code 'block'
getit ?
'g'
|
|
|
|
|
Look up the syntax for an if(){}else{} statement.
(Oops! I gave it away)
Bram van Kampen
|
|
|
|
|
I already tried to walk him through it - and Im in an unusually generous mood (wont last long, but he gets the benefit )
'g'
|
|
|
|
|
Hi,
I just got your post after I posted Mine. Happens often for some reason, I see a single question, No replies, Make a reply, and then the thread expands...
No harm intended though.
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: No harm intended though.
of course not - thats what makes it fun !
'g'
|
|
|
|
|
Bram van Kampen
|
|
|
|
|
Maybe you're single-stepping your keyboard too much?
|
|
|
|
|
No,
It is a Syntax Error: The OP Wrote:
if(X>Y){...}else(X<=Y){...}
The Compiler responded with Missing ';' before '{'
So he wrote:
if(X>Y){...}else(X<=Y);{...}
This makes it valid Code, but the final Block will never be executed.
Bram van Kampen
|
|
|
|
|
I was reacting on your "Happens often for some reason..."
the original problem has been solved already.
|
|
|
|
|
First a side comment on terminology.
rbwest86 wrote: int main()
{
//Global Declarations of Variables
double iovertime_hours=0;
double iovertime_pay=0;
These are actually automatic (local) variables, not global. There is nothing wrong with this - you normally do want to use automatic variables rather than global whenever you can.
Now to your question.
rbwest86 wrote: int cname ;
int ihours ;
int iwage ;
//Enter Employee Information
cout << "\n\nEnter the employee name = " ;
cin >> cname ;
Note that cname is an int. I would normally expect the response to the prompt to be a string. You are telling cin to expect only a number. Perhaps cname should be something like, oh, a std::string.
|
|
|
|
|
Thank you all so very much. I figured it out with the support of everyone here.
There were two major problems. Problem one was the:
int cname "this should have been a string"
The other problem was I included what should have been a comment:
else
{
code here
}
And thats it!
Thank y'all so very much. Now I gotta figure out a way to keep the console open that is not operating system Dependant, or should I say non-extended C++? I tried cin.get() and cin.ignore() but those didn't work and think they are OS Dependant.
V/R
Rob
|
|
|
|
|
Just to let everyone know, I included a do-while loop to ask the user if he wanted to include another entry. I did not want to use some sort of OS dependent rule to get my program to stop closing.
|
|
|
|
|
my code:
#include "stdafx.h"
#include <stdio.h>
#include <fstream>
void CParamDisplay::OnParamOpen()
{
CFileDialog cfiledlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
, "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||", this);
if (IDOK == cfiledlg.DoModal())
{
m_filename = cfiledlg.GetPathName();
UpdateData(FALSE);
DisplayParam(m_filename);
}
}
BOOL CParamDisplay::DisplayParam(CString filename)
{
UINT sNum = 0;
CHAR paramId[MAX_BUF_SIZE] = _T("");
CHAR paramUnit[MAX_BUF_SIZE] = _T("");
FLOAT paramValue = 0;
FILE* pFile = fopen (filename, "r");
if(pFile == NULL)
return FALSE;
while(fscanf(pFile, "%d %s %s %f", sNum, paramId, paramUnit, paramValue) != EOF)
{
...
}
fclose(pFile);
return TRUE;
}
when i debug it, the app stopped at fscanf().and displayed:"Uhandled exception in XX.exe (MSVCRTD.DLL):0XC00000005:access violation".i can't fix it...(T_T)
i 've tried ,then i have no regret
|
|
|
|
|
what is MAX_BUF_SIZE defined as ?
what does your data in the file look like ?
the access violation reported is most commonly caused by overwriting memory somehow - not allocating it/enough - I can see you are allocating buffers for your char (string) arrays, but for instance if
MAX_BUF_SIZE was 5 and you had
1 thisisacharastring thisisanothercharstring 1.44
you'd see that the first %s in fscanf would get thisisacharastring which is a bit longer than 5
'g'
|
|
|
|
|
thank u, i've tried the Bram van Kampen's method,it works
i 've tried ,then i have no regret
|
|
|
|
|
try:
while(fscanf(pFile, "%d %s %s %f", &sNum, paramId, paramUnit, ¶mValue)...
Bram van Kampen
|
|
|
|