|
The "virtual" mechanism depends on the VTable, which will be setup by the constructor. So, the constructor itself cannot be virtual (not with C++), even though you could try something like this[^]. The link that I've provided to you is among one of the best C++ FAQs on the internet. You may as well refer to it to read about Virtual destructors and other basic C++ stuff.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
In addition to Rajesh' reply: when you construct your object, you always know the type of object you want to create at that time (you always call a specific constructor, not the one from the base class). So, it doesn't make sense to have a virtual constructor.
Virtual destructors make more sense: when you destroy your object, you often manipulate objects as a pointer to their base class (typical scenario where polymorphism is used). In that case, you want to call the correct version of your destructor.
|
|
|
|
|
Consider this Example
class Base
{
};
class Derived: public Base
{
};
Consider this Base *b = new Base()
This means we need to create a Base object we are really not worried on who has derived from Base.
Consider this Derived *d = new Derived(); or Base *b = new Derived();
This mean we want a derived object and by default the base class constructor is called before the Derived.
So there is no use of virtual constructors.
-Arun
|
|
|
|
|
Is it possible to write an array function that returns long strings (300-600 characters) in Excel? I have tried writing a C++ dll with Excel C API and also using VBA, but get #VALUE! error if I do not truncate the strings to 255 characters. Using VBA, I have found that it is possible for single cell function.
For I = 1 To 2056
Query = Query & "A"
Next I
LongStringFunction = Query
modified on Saturday, June 13, 2009 5:25 AM
|
|
|
|
|
Hello!
Firstly, this has nothing to do with C++. But since that you're here, I'll propose a C++ solution, which will work if a cell has more than 255 characters. I've used this class and it just works: BasicExcel - A Class to Read and Write to Microsoft Excel[^]
There may be drawbacks and gotchas, but I'll expect you to read through the article to understand it.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks; I'll give the article a read as I'm always interested in other ways to control excel.
I've clarified my question; I am trying to write a C++ dll using Excel C API.
VARIANT _stdcall TestFunction(VARIANT ARG1, VARIANT ARG2); //results may contain strings between 300-600 characters.
|
|
|
|
|
TedChangKorea wrote: I've clarified my question; I am trying to write a C++ dll using Excel C API.
In that case, I hope the XLW wrapper would be a great reference to you: XLW[^]. Unless you are wanting to rewrite the whole thing, you might as well use XLW to build your DLL.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks; XLW looks like it should work. I was able to make a quick single cell function that returned a long string. I am going to try using the XLW's CellMatrix to see if I can get an array function to work with long strings.
|
|
|
|
|
It does work and it's a pretty nifty class if you ask me.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Which version of XLW are you using ?
|
|
|
|
|
I am trying to make an smart device MFC application using VS2005. The
VS2005 gave Pocket PC 2003 + some other ones as SDK. But i wanted to make my own SDK and make it work. Why I
wanted this way was that, I have created an OS image ( I had given set
sysgen_mfc=1). Also I created a sample SDK. So I can build my smart
device application using sample sdk , Then download the image. Now i can make the application work fine and for debugging the same I can use emulator.
But I am getting these errors while compling "stdafx.cpp"
C:\Program Files\Windows
CETools\wce600\SDK2\include\ARMV4I\malloc.h(45) : error C2143: syntax
error : missing ',' before '*'
D:\Program Files\Microsoft Visual Studio
8\VC\ce\atlmfc\include\atltime.h(403) : error C3861: 'wcsftime':
identifier not found
D:\Program Files\Microsoft Visual Studio
8\VC\ce\atlmfc\include\atltime.h(430) : error C3861: 'wcsftime':
identifier not found
D:\Program Files\Microsoft Visual Studio
8\VC\ce\atlmfc\include\atlcomtime.h(367) : error C3861: 'wcsftime':
identifier not found
Can anyone know what to do, to resolve these errors.
thanks
|
|
|
|
|
This seems to be compilation error because of not including correct header files.
Try including the required header files in stdafx.h
|
|
|
|
|
Recently i have made a program to apply an neural network 'AND' gate that works like a logical 'AND' gate in c language. here i changed the bias value with fixed weights variable.
but now i want to change both bias and weight value for this problem. i need code. i will be grateful if anybody helps me.
here is the code of my program
#include<stdio.h>
#include<conio.h>
#define true 1
#define false 0
void main()
{
clrscr();
int i,store[10],z=false,p,l=0,k=0,x1[4]={0,0,1,1},x2[4]={0,1,0,1},w1=1,w2=1,out[4]={0,0,0,1},check=0;
float bias=0.0,result;
printf("\n");
while(z==false)
{
for(i=0;i<4;i++)
if((x1[i]*w1+x2[i]*w2+bias)<0)
store[i]=0;
else
store[i]=1;
printf("\n");
for(i=0;i<4;i++)
printf("%d",store[i]);
printf("\tbias value\t");
printf("%f",bias);
check=0;
for(i=0;i<4;i++)
{
if(out[i]!=store[i])
{
if(store[i]==1)
bias=bias-.05;
else
bias=bias+.05;
z=false;
}
else
{
check++;
if(check==4)
z=true;
else
z=false;
}
}
}
getch();
}
|
|
|
|
|
Hi,
I've been trying to search a multidimensional array and have been unsuccessful.
I get the following error:
"Only single dimension arrays are supported here."
using this code:
Array.IndexOf(serverRecords, x);
where serverRecords is 2d array.
Anyone know how to do this??
Any help would be greatly appreciated!
-Paul C.
|
|
|
|
|
As the .NET documentation and the error message say, Array.IndexOf only works on one-dimensional arrays. For other arrays, you will have to create search code yourself.
And why did you ask on this forum, which deals with native C/C++, not C#???
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hey Dude,
The question is not clear.Can you put the full code block you wrote?
Wonde T.
ASP Net
|
|
|
|
|
Sorry for the delay..
What I'm trying to do is this: I want to be able to do is click an item in a list, determine which item in the list was clicked (which I'm able to do with the 'selectedItems' property of the listView object), and use the text property of that item to search a multidimensional array. If I click on 'Server A', I want to search with a foreach and find the element that has the string 'Server A'..
And then find all the OTHER associated information with it, such as the IP Address or the resource info or the User associated with it...
Thanks for any help on this one!
[1]["Server A"]
[1]["192.168.0.1"]
[1]["pic.gif"]
[1]["Bob"]
[2]["Server B"]
[2]["192.168.0.2"]
[2]["pic2.gif"]
[2]["Joe"]
and so forth..
public partial class Form1 : Form
{
String[,] contactRecords = new String[50, 3];
String[,] serverRecords = new String[50, 4];
public Form1()
{
InitializeComponent();
}
public void importSettings(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("contact.data");
String line = sr.ReadLine();
String[] lineSplit = line.Split(',');
for (int i=0;line != null; i++)
{
lineSplit = line.Split(',');
contactRecords[i, 0] = lineSplit[0];
contactRecords[i, 1] = lineSplit[1];
contactRecords[i, 2] = lineSplit[2];
line = sr.ReadLine();
}
for (int x = 0; contactRecords[x, 0] != null; x++)
{
CLB_Contact.Items.Add(contactRecords[x, 0]);
}
sr.Close();
StreamReader sr2 = new StreamReader("servers.data");
String line2 = sr2.ReadLine();
String[] lineSplit2 = line2.Split(',');
for (int j=0; line2 != null; j++)
{
lineSplit2 = line2.Split(',');
serverRecords[j, 0] = lineSplit2[0];
serverRecords[j, 1] = lineSplit2[1];
serverRecords[j, 2] = lineSplit2[2];
serverRecords[j, 3] = lineSplit2[3];
line2 = sr2.ReadLine();
}
for (int x = 0; serverRecords[x, 0] != null; x++)
{
Servers_LV.Items.Add(serverRecords[x, 0]);
}
sr.Close();
}
public void helloWorld(object sender, MouseEventArgs e)
{
ListView.SelectedListViewItemCollection list = Servers_LV.SelectedItems;
foreach (String x in serverRecords)
{
if (x == list[0].Text)
{
TB_IPAddress.Text = x;
Array.IndexOf(serverRecords, x);
}
}
}
}
|
|
|
|
|
Hi,
It may be very long time to answer this question. I have put a code snippet as follows.
private void helloWorld_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection list = Servers_LV.SelectedItems;
int firstIndex = 0, secondIndexer = 0;
if (list.Count <= 0)
return;
foreach (String x in serverRecords)
{
if (x == list[0].Text)
{
TB_IPAddress.Text = serverRecords[secondIndexer, 1];
return;
}
firstIndex++;
if (firstIndex % 4 == 0)
secondIndexer++;
}
}
Wonde Tadesse
MCTS
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Could some gurus tell me if this is possible?
|
|
|
|
|
Hello everybody
I am looking for the rand() function definition, because I want to use it to create a similar
function for a super secret project of mine . I have found a website on the Internet that
claims the rand() function definition is something like:
unsigned long int next = 1;
int rand()
{
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}
however if I use this function it does not give me the same value as the rand() function.
cout << (rand() %50) << "\n";
cout << (rand() %50) << "\n";
gives the first random value of 41 and second value of 17. (the srand() function was not used so these are the same every time I run the program)
and when I use the definition I got from the website
long unsigned int Getal = 1;
Getal = (Getal*1103515245 + 12345);
cout << (Getal/65536) % 32768 % 50 << "\n";
Getal = (Getal*1103515245 + 12345);
cout << (Getal/65536) % 32768 % 50 << "\n";
the first output is 38 and the second 8.
Maybe there is something wrong with my implementation, or can someone maybe help or tell me what the
correct definition is. I am using Visual C++ 6 and use the rand() function found in the stdlib.h.
Is the data types I used correct? Where can I find the definition in the stdlib.h? I tried looking
there but there's only a line that says "_CRTIMP int __cdecl rand(void);" ?!? Anyway I would
appreciate help
thanks
grimes
KOM UIT DAAAAA!!!
modified on Friday, June 12, 2009 1:04 PM
|
|
|
|
|
Hi,
I could come up with an infinite number of pseudo-random-number-generators; they all are periodic, i.e. after N calls they repeat the sequence; you would hope N to be large.
The simple ones have a single state variable (next in your snippet) that is operated upon (e.g. with multiply and add; or with shift and exor) and result in a period of at most 2^B for a state variable holding B bits.
I can't tell you which one is used in the standard libraries, maybe because that is super secret too.
I suggest you Google rand.c to get a small collection.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
The reason I said it is super secret is so that when the CIA/FBI/NSA kick down your door to arrest you as one of my accomplices, you can have deniability.
I thought that there was a simple random function that most programmers, that are too lazy to make their own, use. Perhaps you know of a method to predict the next number of a randomizer function. This is why I wanted to know the definition of the rand() function so I can write a program to predict the next 'random' number in a series.
but thanks anyway...
by the way, after this conversation, your phone might be tapped...
KOM UIT DAAAAA!!!
|
|
|
|
|
Grimes wrote: I am looking for the rand() function definition
You failed to mention what compiler you are using. Your in luck, I have several installed.
Visual Studio 6:
C:\Program Files (x86)\Microsoft Visual Studio\VC98\CRT\SRC\RAND.C
Visual Studio 2005:
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\crt\src\rand.c
Visual Studio 2008:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\crt\src\rand.c
You could also take a look at the rand implementation in the GNU LibC library[^]. The rand functions are located in the \glibc-XX\stdlib folder.
Best Wishes,
-David Delaune
|
|
|
|
|