|
That is not my understanding, unless you are using a compiler where ClassName has a very specific predefined meaning. I was assuming that was just meant as a synonym for the actual class rather than a keyword. E. g. this should work:
class foo {
int val;
public:
foo(int v) : val(v) {}
int get() const { return val;}
};
class ABC {
foo obj1;
public:
void AssignValue(foo* ptr) {
obj1 = *ptr;
}
};
At least my compiler accepts it.
|
|
|
|
|
You are correct; I had to add default constructors (MS C++), but it then did what was required.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Yes, but this changes obj1 , which may or may not be what the original question didn't want (if the object is expensive to copy, making it a pointer rather than object, as previously suggested, might be the better solution).
If AmbiguousName has worked more with C# or Java, where the references are implicit, working with pointers might be confusing.
|
|
|
|
|
Well, not only his name is Ambigous, his inquiry is, too: it isn't clear whether his problem is that he cannot assign to obj1, or that he cannot assign it from a pointer. Anyway, the solutions have been pointed out, he just needs to pick the right one.
|
|
|
|
|
Have you tried to change that line of code to this
obj1 = *ptrValue;
This will make your obj1 member variable be a copy of the object that is pointed to by ptrValue.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
So have you tried creating an assignment operator in the ClassName class?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
AssignValue is a clear hint of what you intend to do: assign to the object obj1 the value held by the object pointed by ptrValue , hence
void AssignValue(ClassName* ptrValue)
{
obj1 = *ptrValue; }
Note you should define the ClassName assignment operator in order to make such code work.
Veni, vidi, vici.
|
|
|
|
|
Much clearer answer, I think.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Hello Friends
I was using code
void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
{
FrameWnd::OnInitMenuPopUp( a,b,c);
}
And this one displaying MenuItems correctly.
Now,i trying to add icons to MenuItems.So for that I am using extenal CoolMenuManager to show up Icons with menuItems.
Here is code for this :
void CMainFrame::OnInitMenuPopup(CMenu* a, UINT b, BOOL c)
{
if(m_menuManager.InitMenuPopup(a,b,c))
FrameWnd::OnInitMenuPopUp( a,b,c);
}
Now, in this case,If i use External fn then only icons are showing up. But as now, i am calling frameWnd::OnINitMenupopup too then icons are coming and strings are not coming properly and only for some menuItems and even menuList is coming Wider covering whle screen.
Any Ideas?
Regards
Yogesh
|
|
|
|
|
Without knowing what CoolMenuManager does it is impossible to even hazard a guess.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hello
I found something interesting tht icons and text of menuItem is coming fine Except the menuList. As i click on any menu,menuList pops up and that list is coming wider,covering almost full screen.
I checked that OnMeasureItem which calculates ItemWidth and height is Having some Prob.As I Converted this from VC6 to VS2010.
BOOL CCoolMenuManager::OnMeasureItem(LPMEASUREITEMSTRUCT lpms)
{
ASSERT(lpms);
CMyItemData* pmd = (CMyItemData*)lpms->itemData;
ASSERT(pmd);
if (lpms->CtlType != ODT_MENU || !pmd->IsMyItemData())
return FALSE;
if (pmd->fType & MFT_SEPARATOR) {
lpms->itemHeight = GetSystemMetrics(SM_CYMENU)>>1;
lpms->itemWidth = 0;
} else {
CWindowDC dc(NULL); CRect rcText(0,0,0,0);
CFont* pOldFont = dc.SelectObject(GetMenuFont());
dc.DrawText(pmd->text, rcText, DT_MYSTANDARD|DT_CALCRECT);
dc.SelectObject(pOldFont);
lpms->itemHeight= max(GetSystemMetrics(SM_CYMENU), rcText.Height());
int cx = rcText.Width(); cx += CXTEXTMARGIN<<1; cx += CXGAP; cx += m_szButton.cx<<1;
cx -= GetSystemMetrics(SM_CXMENUCHECK)-1;
lpms->itemWidth = cx;
CMTRACE(_T("OnMeasureItem for '%s':\tw=%d h=%d\n"), (LPCTSTR)pmd->text,
lpms->itemWidth, lpms->itemHeight);
}
return TRUE; }
or u can refer to this link
http://www.codeforge.com/read/89577/coolmenu.cpp__html[^]
Regards
Yogesh
|
|
|
|
|
I found tht Drawtext with parameter DT_CALCRECT is not returning right parameters of rectangle.
Any Ideas ?
|
|
|
|
|
Sorry no, what values does it return and what values do you think it should return?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Mark, I want to research it.
|
|
|
|
|
Dear All
I wrote an application some time back in Visual C++ 6 and used Chartfx for some stuff. It works fine on XP as long as you register the cfx4032.ocx and the sfxbar.dll using regsvr32 prior to running it. I now need to run the application on Win7 32 bit. The application itself seems to run but I can't get a DLLRegisterServer failed 0x80020009 error when I try to register the cfx4032.ocx and sfxbar.dll using regsvr32.
Are there newer version of the ChartFx stuff that I can use without recompiling the application or some other way that I can solve this problem. I need the application in a few weeks time for a training course and then not much there after so I am reluctant to put too much effort it.
Thanks for any help that you can provide.
Regards
Andrew Hoole
|
|
|
|
|
Andrew Hoole wrote: ...but I can't get a DLLRegisterServer failed 0x80020009 error when I try to register the cfx4032.ocx and sfxbar.dll using regsvr32. I assume you meant you do get an error.
Does regsvr32 need to be run as an administrator on the Win7 box?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Sorry yes I certainly do get an error. Not sure about the Administrator thing I'll have to give it a go.
|
|
|
|
|
Yes it would appear that running it as administrator solves the problem.
Thanks
|
|
|
|
|
As mentioned in the other answer, you will need to run regsvr32 as administrator on Windows 7 to register the ocx control.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Chartfx, first time I know it.
|
|
|
|
|
Hi all:
I have run the program successfully in the Linux
but it failed in the solaris, the program will exit after creating process.
I don't known the different between the solaris and linux.
The output when running the programm:
9
10
2
3
4=3374
9
10
1=3373
The part code as following.
// unix daemon
#include <fcntl.h>
#include <sys resource.h="">
#include <stdio.h>
#include <stdlib.h>
#include <sys types.h="">
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <sys stat.h="">
#include "SPSServiceApp.h"
#define LOCKFILE "/var/run/SPSService.pid"
#define LOCKMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
void daemonize(const char* cmd)
{
int i, fd0, fd1, fd2;
pid_t pid;
struct rlimit rl;
struct sigaction sa;
// Clear file creation mask
umask(0);
// Get maximum number of file descriptors
if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
{
fprintf(stderr, "%s: can't get file limit", cmd);
exit(1);
}
if ((pid = fork()) < 0)
{
fprintf(stderr, "%s: can't fork", cmd);
exit(1);
}
else if (pid != 0) //parent
{
printf( "1=%d\n", getpid());
//printf( "1ppid=%d\n", ggetpid());
exit(0);
}
setsid();
printf( "2\n");
// Ensure future opens won't allocate controlling TTYs.
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGHUP, &sa, NULL) < 0)
{
fprintf(stderr, "%s, can't ignore SIGHUP", cmd);
exit(1);
}
printf( "3\n");
if ((pid = fork()) < 0)
{
fprintf(stderr, "%s: can't fork", cmd);
exit(1);
}
else if (pid != 0) //parent
{
printf( "4=%d\n", getpid());
//printf( "4ppid=%d\n", ggetpid());
exit(0);
}
printf( "5\n");
if (rl.rlim_max == RLIM_INFINITY)
{
rl.rlim_max = 1024;
}
for (i = 0; i < rl.rlim_max; ++i )
{
close(i);
}
printf( "6\n");
fd0 = open("/dev/null", O_RDWR);
printf( "7\n");
fd1 = dup(0);
fd2 = dup(0);
if (fd0 != 0 || fd1 != 1 || fd2 != 2)
{
printf( "8\n");
exit(1);
}
}
int lockfile(int fd)
{
struct flock fl;
fl.l_type = F_WRLCK;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;
return(fcntl(fd, F_SETLK, &fl));
}
int already_running(void)
{
int fd;
char buf[16];
fd = open(LOCKFILE, O_RDWR | O_CREAT, LOCKMODE);
if(fd < 0)
{
exit(1);
}
if (lockfile(fd) < 0)
{
if (errno == EACCES || errno == EAGAIN)
{
close(fd);
return(1);
}
exit(1);
}
ftruncate(fd, 0);
sprintf(buf, "%ld", (long)getpid());
write(fd, buf, strlen(buf) + 1);
return(0);
}
int main(int argc, char* argv[])
{
char* cmd;
struct sigaction sa;
printf("9\n");
if ((cmd = strrchr(argv[0], '/')) == NULL)
{
cmd = argv[0];
}
else
{
++cmd;
}
// Become a daemon
printf("10\n");
daemonize(cmd);
printf("11\n");
// Make sure only one copy of the daemon is running
if (already_running())
{
exit(1);
}
printf("12\n");
sa.sa_handler = SPSServiceApp::sig_term;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGHUP);
sa.sa_flags = 0;
if(sigaction(SIGTERM, &sa, NULL) < 0)
{
exit(1);
}
printf("13\n");
sa.sa_handler = SPSServiceApp::sig_hup;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGTERM);
sa.sa_flags = 0;
if(sigaction(SIGHUP, &sa, NULL) < 0)
{
exit(1);
}
wxEntry(argc, argv);
printf("14\n");
exit(0);
}
|
|
|
|
|
The first thing you should do is to edit your question and put proper <pre> tags around your code so it is readable. The second thing is to explain exactly what the program is doing and where it terminates.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi. I have assignment to find difference between Min and Max of an array of 5 numbers. I did some work, but after compiling - my program does not run, it just stops working.. Can you help me, where is my mistake ? Array values needs to be double.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int size;
double array [i];
double min;
double max;
double difference;
printf("Enter the size of the array: ");
scanf("%d",&size);
printf("Enter %d elements in to the array: ", size);
scanf("%d",&array[i]);
max = array[0];
for (i=0; i<size; i++)
if (max < array [i])
max = array [i];
{
printf("Maximum value is: %d\n",max);
}
min = array [0];
for (i=0; i<size; i++)
if (min>array[i])
min = array [i];
{
printf("Minimum value is: %d\n",min);
}
difference = max - min;
printf ("Difference between Min and Max values is %d\n", difference);
system("PAUSE");
return 0;
}
|
|
|
|
|
I've not looked terribly close, but please start by putting { }'s around your for loop blocks.
for example;
for (int i = 0; i < size; i++)
{
}
|
|
|
|
|
Mikerush7 wrote: Array values needs to be double.
then this is wrong:
Mikerush7 wrote: scanf("%d",&array[i]);
|
|
|
|
|