|
That is fine. However make sure you don't need a hierarchy where the base class implements the (int,bool) ctor and the derivations can call it using the initialization list.
class base
{
protected:
base(int n, bool b);
};
class myclass : base
{
public:
myclass();
};
myclass::myclass():base(1,true){}
Also check out Scott Meyers book Effective C++ for things like this and much more.
|
|
|
|
|
|
Mike the Red wrote: I couldn't find any documentation telling me I couldn't do it that way, but it was definately causing problems.
Such as? I used your class like the following and the constructors behaved as expected:
void main( void )
{
C c1;
C c2(1);
C c3(2, TRUE);
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I guess he want like java constructor like these;
class A {
public A(int a, int b, int c) {
}
public A(int a, int b) {
this(a, b, 0);
}
public A(int a) {
this(a, 0, 0);
}
}
|
|
|
|
|
You want C++ 0x[^]. Unfortunately, it's not finalised, much less fully implemented
I would use the 'constructor method' approach personally.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: much less fully implemente
Yeah, I already checked 2008 feature pack, not there.
|
|
|
|
|
They're not going to be in VS2010 either, AFAIK - it'll have some C++0x features, but not that one.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
That's not good news. But at least tomorrow is still FRIDAY!
|
|
|
|
|
The issue is that a standalone constructor call is creating a new instance that you do nothing with, then exits not having actually initialized anything in the instance it was called for.
It may be a bit of a hack, but for my class I was able to get away with the method below. Really, though, anything with a properly overloaded operator= should be fine, I think.
CClass::Class()
{
int iDefault = 1000.0f;
*this = Class( iDefault );
}
Edit: Frankly, though, I feel like I'm brain-farting on something here. I, too, expected it to work like you originally detailed.
modified on Friday, June 5, 2009 2:19 PM
|
|
|
|
|
Hi there,
I might be in the wrong place here, but lacking another idea where to post, I give it a shot.
I am presently developing in the audio/speech streaming area. I built a TTS system that works quite nicely, streaming (via RTP) the audio in small data packages, which contain the samples. Each 16-bit linear sample is stored in a short.
Now I was wondering if there is any possibility to somehow calculate how long the resulting audio file will be (or was), in miliseconds.
There are programs that do it, like Audacity, so I should be able to get there, as well. Only I don´t have a clue.
Any ideas?
Souldrift
|
|
|
|
|
If you're creating the samples in your own system, then surely you should be able to just work it out from no. samples / sample rate. (* 1000 if you want it in milliseconds.)
Or are you using an external library or app to create the audio?
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
Haha, of course, it´s so easy. I found out myself just now.
But thanks a lot. Your hint was the one I was looking fro.
I am actually using an external lib to synthesize the text. But of course I have the number of samples and the sample rate.
Thanks again ... and I just found this (if anyone is interested) to verify my own calculations:
http://www.angelfire.com/ga/bunnycymru/sound.html[^]
Cheers
Souldrift
|
|
|
|
|
Hi
What kind of reason will cause program crashed at:
CWnd* CWnd::GetDlgItem(int nID) const
{
-----> ASSERT(::IsWindow(m_hWnd));
}
Thank you very much,
|
|
|
|
|
|
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Did you call GetDlgItem after CDialog::OnInitDialog processed? The m_hWnd will not be created before that called.
Check the m_hWnd value is NULL or not.
|
|
|
|
|
Yes, I call GetDlgItem in dialog implementation. But It crashed.
What is going on?
Thanks,
|
|
|
|
|
check;
1) m_hWnd was NULL or not?
- if it was NULL, dialog window has not been created yet.
- if not NULL, some other code overwrite the member. (might be memory bug)
2) GetDlgItem should not call in dialog constructor but can do in OnInitDialog or after this processed.
- this is conclusion from above NULL reason.
|
|
|
|
|
Hi,
I try to initialize an array with a function return, but i get error C2057: expected constant expression. Is there an easy solution for the following problem?
const int iRecordCountBefore = p_rs->GetRecordCount();
int iRsPositionsUpdated[iRecordCountBefore] = {-1};
Thanks you!
|
|
|
|
|
You cannot write such array code in C or C++ program syntax.
You should change like below;
const int iRecordCountBefore = p_rs->GetRecordCount();
int* iRsPositionsUpdated = new int[iRecordCountBefore];
int* iRsPositionsUpdated = (int*)malloc(sizeof(int)*iRecordCountBefore);
memset(iRsPositionsUpdated, -1, sizeof(int)*iRecordCountBefore);
|
|
|
|
|
Thank you for the working and fast answer!
|
|
|
|
|
Don't forget to delete (if you used new) or free (if you used malloc) the memory when you don't need it anymore, otherwise it might lead to memory leaks.
|
|
|
|
|
Can I suggest using a std::vector rather than an array, if only so you don't need to bother remember freeing memory? This will create a vector initialised with iRecordCountBefore integers, all set to -1.
const int iRecordCountBefore = p_rs->GetRecordCount();
std::vector<int> iRsPositionsUpdated(iRecordCountBefore, -1);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
The VS2008 dialog event wizard has stopped working. Double-clicking on a button in an MFC dialog project does not fire the wizard as usual and a right-cliok to get to the 'Add Event Handler...' shows a dialog with no message types.
Further to this the MFC message mapping and virtual class listing that generally appears in the properties window (Alt + Enter) is now empty.
Has anyone elese seen this and if so, how'd they fix it? I have 'repaired' my VS08 installation ...
Thx++
Jerry
|
|
|
|
|
Have you recently installed IE8? That thoroughly shafted code wizards on my PC. I fixed it using this approach[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|