|
I have got a template class. It's called ObArray and one of the datamembers are a pointer to an array of any type of object. At the moment ObArray is just constructing all the objects using the default constructor.
But I always want to have the option to use another constructor to initialize the objects, not just the default one. I want this because it's faster than first creating the objects using te deafult constructor, and then change all the objects. Another reason is that not all classes even have a default constructor, which makes it impossible to create an array of instances of those classes.
The only way I can imagine this to be solves is by sending the constructin info along with the constructing of the array object (ObArray). Since constructors of course take a variable number of arguments, the constructor of ObArray must accept that too.
Like 'ObArray<t>::ObArray(int initLen, ...)', and then this constructor sends the arguments along to the constructor of each of the objects. Is this possible in any way?
Sprudling
|
|
|
|
|
Like 'ObArray::ObArray(int initLen, ...)', and then this constructor sends the arguments along to the constructor of each of the objects. Is this possible in any way?
No. Use placement new instead.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Uhm... I don't really understand what you mean.
I know I can't actually write 'ObArray::ObArray(int initLen, ...)'. I just meant that this constructor could take arguments like that, and pass them on...
Btw... I think I found some sort of solution by using copy constructors, but that requires that the class I want to create the array of has one.
Another solution not requiring that will be better.
Sprudling
|
|
|
|
|
I mean that you should allocate raw memory for all objects first using ::operator new or malloc. Constructors are not called in this phase. You use placement new next to initialize objects in allocated memory. The only problem left is that different classes you're going to put into ObArray may need different number of constructor parameters - you can solve this by providing multiple ObArray constructors, each having different number of params. Assuming that there are max 3 parameters that you need to pass, declaration of ObArray should begin like this:
template <typename T,
typename P1 = void,
typename P2 = void,
typename P3 = void>
class ObArray
{
};
Of course, you can generalize this to use more than 3 parameters in the c'tor.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi...
How can I convert an Integer to LPSTR
here is what I want:
TextOut(hdc, 20, 20, Integer, 5);
|
|
|
|
|
With itoa(nVal, buff, 10);
Where buff is a LPSTR and nVal is a Integer.
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
|
I looked everywhere and tried alot of different things, but I can't
find any code that will help me create a multiline CListCtrl in
report mode. Any ideas? Any suggetsions? Any code?
Any response any one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
Its possible.
http://www.codeguru.com/listview/ReportCtrl.shtml
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I sincerely appreciate the reply.
I looked at that demo project and its spectacular, but really different
understand. By chance, do you have a smaller project that isolates the multiple text for one item feature? Or could you help me create it?
I have a CListCtrl and one of my columns has lots and lots of text. Horizontal scrolling to the right is just not doing it. But if I could make the text go to a new line within that same item, then the user could read the CListCtrl clearly.
Please, please any response you can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
While not exactly a programming question, I'd like to know if you can turn off auto-word selection.
What I'm talking about is when you're programming and trying to select text and it will back-up the start and/or finish to whereever it thinks is appropriate. "Word selection" I think they call it. Can I disable this system-wide?
Thanks
|
|
|
|
|
Hi
how can I read a single line from a text-file?
There should be read in so much characters until there is a carriage-return/line-feed.
How to do this?
|
|
|
|
|
CFile::ReadString, fread, etc..
try the MSDN. search for "read a line from a file"
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
ReadString works fine
Thanks!
|
|
|
|
|
There is a simple (and fast) solution for this in C
#include "stdio.h"
FILE *filepointer;
char line[100];
char *kar;
fp1 = fopen("yourfilenamewithpath", "r");
kar = fgets(line, 100, filepointer); //read one line
//kar = fscanf(p, "%s", word); reads just one word until next space
//kar = getc(filepointer); reads just one character
printf("%s", line);
fclose(filepointer);
Bunburry
Education is an admirable thing but it is well to remember from time to time that nothing that is worth knowing can be taught (O.Wilde)
|
|
|
|
|
Sirs,
do you have an idea how to create a view like the output window of Visual C++ with white tabs and client area to write on?
Thank you for your kind help.
Bunburry
Education is an admirable thing but it is well to remember from time to time that nothing that is worth knowing can be taught (O.Wilde)
|
|
|
|
|
See into BCG control, you can find it into CodeProject
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Delphi can not use my lib file so how can I provide dll that I wrote in vc++ to client that works in Delphi ????
My dll exporting c style functions that use in objects of c++ {classes).
So what can I do if I want to give this dll for Delphi ???
|
|
|
|
|
non-MFC clients can only use plain C functions from DLLs. or, you could write it as a COM module. you cannot export C++ functions to non-C++ clients.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Maybe these will help: (?)
http://www.drbob42.com/delphi/headconv.htm
http://www.mindspring.com/~cityzoo/tips/loadlib.txt
|
|
|
|
|
|
Hello,
I am trying to implement a multimedia timer in my app.. So far I think most of what I have done is correct but I am having a few problems.. I have been refrencing http://www.codeproject.com/system/timers_intro.asp#MMTimers and it has helped out quite a bit.. Here is what I have implemented so far..
OnStart()
{
.
.
.
TIMECAPS tc;
timeGetDevCaps(&tc, sizeof(TIMECAPS));
DWORD resolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
timeBeginPeriod(resolution);
timeSetEvent(iS,resolution,TimerFunction,(DWORD)this,TIME_PERIODIC);
void CTimerDlg::MMTimerHandler(UINT nIDEvent)
{
iS --;
m_timer2.Display(iS,iM,iH,iD,(CString)m_strTimer2="%D:%H:%M:%S");
}
void CALLBACK TimerFunction(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CTimerDlg* obj = (CTimerDlg*) dwUser;
obj->MMTimerHandler(wTimerID);
}
When compiling I get a error that states "'timeSetEvent' : cannot convert parameter 3 from 'void (unsigned int,unsigned int,unsigned long,unsigned long,unsigned long)' to 'void (__stdcall *)(unsigned i
nt,unsigned int,unsigned long,unsigned long,unsigned long)'"
Anyone know what the problem may be?
Thanks again for helping out!
Rob
|
|
|
|
|
|
I just thought this code is correct, but my app crashes. Here it is:
void Log()
{
FILE *log;
if((log = fopen("C:\\foo.log","a+t")) == NULL)
return;
SYSTEMTIME systime;
GetSystemTime(&systime);
char text[128];
sprintf(text,"%s.%s.%s\t%s:%s",systime.wDay,systime.wMonth,systime.wYear,systime.wHour,systime.wMinute);
size_t len = strlen(text);
fwrite(text,sizeof(char),len,log);
fclose(log);
}
any help is apreciated
|
|
|
|
|
what is 'len' ? (0? 10,1000,000 ?)
any chance you've overrun the 128 characters? (use snprintf to be safe).
also, why not just use fprintf, instead or using a temp buffer ?
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|