|
In that case have a default constructor for initialization and add a function BillingDates::Open (std::string& file) that gets called when you have the path to your file.
You might also need something like bool BillingDates::IsOpen() const to check the state of the object.
Mircea
|
|
|
|
|
Have you tried:
BillingDates bData2("");
BillingDates* bData = &bData2;
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi and thanks for replying but the problem I have is I don't know the path to my input file until later in the program
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Then add an empty constructor and a "setter" method to the 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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
If they need to be the same instance, versus a copy, consider using std::shared_ptr for both.
|
|
|
|
|
|
Hi there, I don't think I'm explaining what is confusing me so I'll try again.
If I define a class object in a C# program I can instantiate it like so
Sample of the top of my head code
namespace Test
{
public class Dummy
{
string Path {get;set;}
Public Dummy(string Path)
{
this.Path = Path;
}
}
class Program
{
Dummy dummy {get;set;}
[STAThread]
static void Main()
{
Program p = new Program();
p.dummy = new Dummy("MyPath");
}
}
}
In C++ I can only create it like this if I make the dummy variable a pointer ( which is not a problem but I'd like to know how to do it the other way) I'm sure this must be doable. Thanks for everyones help so far.
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Quote: which is not a problem but I'd like to know how to do it the other way There isn't 'the other way' (AFAIK).
In C++ , using new , you get a pointer. Moreover you need to handle the cleanup of the dynamically allocated memory:
#include <iostream>
using namespace std;
namespace Test {
class Dummy
{
string path;
public:
Dummy(string path) : path {path}{}
string get (){return path;}
void set(string newpath){ path = newpath; }
};
class Program
{
Dummy * dummy;
public:
static void main()
{
Program * p = new Program();
p->dummy = new Dummy("MyPath");
cout << p->dummy->get() << "\n";
delete p->dummy;
delete p;
}
};
}
int main()
{
Test::Program::main();
}
You may write the Program destructor to ammeliorate the code, but cleanup is unavoidable.
If you can initialize at once your objects then you could use the stack and the code would be nicer:
#include <iostream>
using namespace std;
namespace Test {
class Dummy
{
string path;
public:
Dummy(string path) : path {path}{}
string get (){return path;}
void set(string newpath){ path = newpath; }
};
class Program
{
Dummy dummy;
public:
Program( Dummy dummy):dummy{dummy}{}
static void main()
{
Program p { Dummy{ "MyPath" } };
cout << p.dummy.get() << "\n";
}
};
}
int main()
{
Test::Program::main();
}
Finally smart pointers allows you to make the two steps initiazlization without the hassle of manual cleanup, e.g.
#include <iostream>
#include <memory>
using namespace std;
namespace Test {
class Dummy
{
string path;
public:
Dummy(string path) : path {path}{}
string get (){return path;}
void set(string newpath){ path = newpath; }
};
class Program
{
unique_ptr<Dummy> dummy;
public:
static void main()
{
Program p {};
p.dummy = make_unique<Dummy>("MyPath");
cout << p.dummy->get() << "\n";
}
};
}
int main()
{
Test::Program::main();
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
In C++, you can define variables at any point, not just at the beginning of the block. Define bData2 only at the point that file name is known.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Correcting the mis-spellings you have:
BillingDates *bData; BillingDates bData2;
In the above code bData is a pointer that has not yet been initialised, so it does not actually point to anything. bData2 is an actual instance of the class, or would be if you had included the no-parameters constructor to get it to compile.
But I am not sure what you are trying to do with them. You could add the following line of code at some point:
bData = new BillingDates("someFilename");
but then what? And it is still not clear what bdata2 is supposed to be for.
|
|
|
|
|
Hi Richard, sorry about the spelling mistakes I'm actually working on multiple project so that was a cut'n past jobbie
I know I can do this
bData = new BillingDates("someFilename");
but how can I create an instance of the class using bData2 ( not in the declaration of the variable I know how to do that ) as I said earlier in C# ypu can declare like
someclass someclassob {get;set;}
Then create the instance
someclassobj = new someclass("Parameter goes here");
even though you didn't specify a parameter in the declaration of someclassobj .
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
pkfox wrote: ypu can declare like
someclass someclassob {get;set;}
That's a new one on me, I must look it up.
As I mentioned you need to add a parameterless constructor to the class, and some method that allows you to add a filename at runtime. something like:
class BillingDates
{
public:
BillingDates();
BillingDates(std::string InputFile);
void addFile(std::string InputFile);
void ProcessDates();
};
You can then write:
BillingDates *bData;
BillingDates bData2;
bData2.addFile("your file name here");
bData = &bData2;
But I really don't know why you need any of that. All you really need is:
BillingDates *bData;
bData = new BillingDates("your file name here");
Does that make (any) sense?
|
|
|
|
|
Hi Richard yes it does and in fact is what I'm currently doing - I think I need to take my C# head off - thanks very much for your time
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
I do think going backwards from C# to C++ is going to mess with your head quite a lot. Good luck.
|
|
|
|
|
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
All,
I have a similar code segment as below, and the problem is that when I drag a file from file explorer, the drag over and the drag enter do not allow me to use the DROPEFFECT_NONE. It is overwritten with a DROPEFFECT of DROPEFFECT_COPY.
BOOL CtestdragDlg::OnInitDialog()
{
CDialog::OnInitDialog();
::OleInitialize(NULL);
BOOL bRes = m_Target.Register(&m_List);
m_cfFormat = RegisterClipboardFormat(_T("{2FCA1C31-D8F1-4f20-8051-B0CCF7B6FD0D}"));
m_List.InsertColumn(0,_T("First"),0,300);
m_List.InsertItem(0,_T("Hello"));
return TRUE;
}
HGLOBAL CtestdragDlg::GetData()
{
char Text[5] = "HHHH";
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE,strlen(Text)+1);
char *pChar = (char *)GlobalLock(hGlobal);
strcpy(pChar,Text);
GlobalUnlock(hGlobal);
return hGlobal;
}
void CtestdragDlg::OnLvnBegindragList1(NMHDR *pNMHDR, LRESULT *pResult)
{
COleDataSource DataSource;
HGLOBAL hData = GetData();
if (hData)
{
DataSource.CacheGlobalData(CF_HDROP,hData);
DROPEFFECT DropEffect = DataSource.DoDragDrop();
}
*pResult = 0;
}
DROPEFFECT CMyTarget::OnDragOver(CWnd* pWnd,COleDataObject* pDataObject,DWORD dwKeyState,CPoint point)
{
return DROPEFFECT_NONE;
}
When the DROPEFFECT_NONE is returned in the OnDragOver event, I get the effect as if it were in DROPEFFECT_COPY. The COLEDragTarget seems to get the correct value back, but then in goes into OLE32 code that I can figure out.
|
|
|
|
|
So is your target window receiving the copy, or is it disallowing it?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
The target window (CTreeCtrl) is returning on the OnDragEnter and OnDragOver a DROPEFFECT_NONE. The cursor is displaying as if I returned a DROPEFFECT_COPY. I can return back other types like DROPEFFECT_MOVE or DROPEFFECT_LINK and those behave properly. The interesting thing is that OnDrop is not called if I do return DROPEFFECT_NONE, and it is called in the case I do DROPEFFECT_MOVE, etc. So the function calling is correct. It is only the cursor that is being displayed that is not correct. Also in this same application within other windows, I am using other implementations (different window types) of COLEDropTarget and the cursor behavior is correct. I have no clue where else to look at this time. As a workaround, I'm using the CImageList Drag concept to display a NOT symbol beside the cursor when DROPEFECT is NONE.
|
|
|
|
|
Hi, I am enumerating my network and printing all server name but for mac system it is returning same OS type as windows so i am not able to differentiate machine. i am getting OS type 4099 for mac which is same for windows. also binary conversion is compatible with all predefined macro as i am doing AND with predefined macro.:java
|
|
|
|
|
Does this have something to do with C/C++? If so, please show the relevant part of the code and explain what is incorrect.
|
|
|
|
|
it will print false details for mac and linux system. we have pre defined check for unix os type but for mac we dont have any. and the os type we are getting for mac also similar to on eof win 10 os version.
printf("\tPlatform: %d\n", pTmpBuf->sv101_platform_id);
wprintf(L"\tName: %s\n", pTmpBuf->sv101_name);
printf("\tVersion: %d.%d\n",
pTmpBuf->sv101_version_major,
pTmpBuf->sv101_version_minor);
printf("\tType: %d", pTmpBuf->sv101_type);
Platform: 500
Name: MACMINI-558088
Version: 6.1
Type: 4099
Platform: 500
Name: WIN1019H2X64
Version: 10.0
Type: 4099
where macmini is a mac system.
|
|
|
|
|
Where and how do you obtain the values you are printing out?
|
|
|
|
|
does netserverenum function retrives mac system too?
|
|
|
|
|
Those values must come from the systems themselves, or be set when the servers are installed on the network.
|
|
|
|
|
Hi,
First let me say that I am a Windows guy so I don't know how to troubleshoot the SAMBA or Apple SMB side of your issue. However I believe that you are looking for the SetServiceBits function[^].
This should allow you or your company (or Apple or Google or whoever wants to use this) to define:
#define SV_TYPE_APPLE_MINI_CUSTOM_TYPE 0x123456789 Both the client and server would need to have this type registered. All I can do is tell you what you need to do on the Windows side.
Have you tried using SV_TYPE_SERVER_UNIX
Looking through the Apple source code[^] I see that they have that one defined.
Update:
1.) Looks like SAMBA uses[^] the 'announce as' in the configuration file to set this value.
2.) Apple code shows that they hard code this value with:
default_server_announce = 0;
default_server_announce |= SV_TYPE_WORKSTATION;
default_server_announce |= SV_TYPE_SERVER;
default_server_announce |= SV_TYPE_SERVER_UNIX;
default_server_announce |= SV_TYPE_PRINTQ_SERVER;
switch (lp_announce_as())
{
case ANNOUNCE_AS_NT_SERVER:
{
default_server_announce |= SV_TYPE_SERVER_NT;
}
case ANNOUNCE_AS_NT_WORKSTATION:
{
default_server_announce |= SV_TYPE_NT;
break;
}
case ANNOUNCE_AS_WIN95:
{
default_server_announce |= SV_TYPE_WIN95_PLUS;
break;
}
case ANNOUNCE_AS_WFW:
{
default_server_announce |= SV_TYPE_WFW;
break;
}
default:
{
break;
}
}
It's located at the very bottom of loadparm.c[^]
So it looks like you will not be able to change this. Maybe you should try an Apple forum instead.
modified 4-Dec-20 5:25am.
|
|
|
|