build in error message for compile time

I would like to build in an error message which should be issued during compilation depending on the value of a variable.

I have defined following class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class rFFT : public QObject
{
public:
    rFFT::rFFT( SLArrayIndex_t FFTLength,					
                const enum SLWindow_t WindowType = SIGLIB_RECTANGLE,
                bool createInternalArrays = true,    // internal working arrays generated within the constructor if true
                QObject *parent = NULL );            // otherwise, arrays should be passed as arguments
	
    rFFT::~rFFT();

    void doFFT( SLData_t *pReal,            // pReal is also input array, will be overwritten!
                SLData_t *pImag );          // works with both versions of rFFT

    void doFFT( SLData_t *pInput );         // works only with an instance of rFFT having internal arrays, pInput is preserved!							
.....
};

the use of the class is as follows:

Version with 'internal arrays':
1
2
3
4
5
// declare and allocate memory for pReal, pImag, pInput
// write some data into pReal and pInput
rFFT myFFTWithInternalArrays( FFT_LENGTH, SIGLIB_HANNING ); // true by default -> generates internal arrays
myFFTWithInternalArrays.doFFT( pReal, pImag );       // OK
myFFTWithInternalArrays.doFFT( pInput );             // OK 

Version with 'external arrays':
1
2
3
rFFT myFFTWithOUTInternalArrays( FFT_LENGTH, SIGLIB_HANNING, false );  // false -> no internal arrays
myFFTWithOUTInternalArrays.doFFT( pReal, pImag );    // OK
myFFTWithOUTInternalArrays.doFFT( pInput );          // LEADS TO ACCESS VIOLATION DURING RUNTIME 


The method void doFFT( SLData_t *pInput ) can only call an instance of rFFT having internal arrays.
Unfortunately, the error is detected at runtime.

I have inserted an error message within the method 'rFFT::doFFT( SLData_t* pInput )':
1
2
if ( ! mHasInternalArrays )
    qDebug() << " === ERROR: use of 'rFFT::doFFT( SLData_t *pInput )' only allowed with rFFT having internal arrays, leads to assertion error! ===" ;

but I would prefer to have the error message already during compile time.
I did'nt find a solution, do somebody see one?

I thank you for your valuable time

Alain
Only way I can think of is if you use different types for objects with and without internal arrays.

1
2
3
rFFTWithInternalArrays myFFTWithInternalArrays( FFT_LENGTH, SIGLIB_HANNING );
myFFTWithInternalArrays.doFFT( pReal, pImag );
myFFTWithInternalArrays.doFFT( pInput );


1
2
3
rFFTWithOUTInternalArrays myFFTWithOUTInternalArrays( FFT_LENGTH, SIGLIB_HANNING);
myFFTWithOUTInternalArrays.doFFT( pReal, pImag ); 
myFFTWithOUTInternalArrays.doFFT( pInput ); // error rFFTWithOUTInternalArrays doesn't have a doFFT function with only one parameter 


You could probably make use of inheritance. Making rFFTWithOUTInternalArrays a superclass of rFFTWithInternalArrays.
Since the variables are computed, assigned, and so on at runtime, it's going to be hard, if possible.
thank you Peter, your proposal is a good way for my case.
I have further methods working only with the rFFT with internal arrays, so the way you proposed is best suited for my purposes.

Alain
Topic archived. No new replies allowed.