need help passing array member.

I have a struct (actually a deftype). One of the members is a fixed 2D array of unsigned characters.

I'm trying to write one function which calls a second function. I cannot modify the structure definition, nor the arguments of the first function. But I am writing the contents of the first function.

One argument of the first function I am given a pointer to the structure. I wish to pass the array (member of structure) to the second function. I am also passing a 3D array to the second function which I declared itself.

typdef struct tagTimedLevel
{
...
unsigned char waveform[2][1024];
...
} TimedLevel;

void function2(unsigned char wf[][1024], signed char sp[][2][1024])
{
...
sp[0][0][0] = wf[0][0]; \ example use of elements.
...
}

int function1(... Timedlevel* pLevel ...)
{
signed char Spect[2][2][1024];
...
function2(pLevel1->waveform,Spect); // I get error here.
...
}


When I compile, I get an error 68: cannot convert parameter 1 from 'unsigned char [2][1024]' to 'unsigned char *[][1024]'

I get no error for parameter 2.

I get same results if I declare function2 with "2" in each empty bracket pair.


Comments

  • The problem is spelling errors. Correct them and it will compile ok.
  • : The problem is spelling errors. Correct them and it will compile ok.
    :

    I might have spelling errors in my post, but not in my actual source code. The structure variable is called "pLevels". I spelled it right everywhere I used it. If there are other spelling errors, where are they?

    If I am missing a symbol ("*", or "&") I need to know where...


  • : I have a struct (actually a deftype). One of the members is a fixed 2D array of unsigned characters.
    :
    : I'm trying to write one function which calls a second function. I cannot modify the structure definition, nor the arguments of the first function. But I am writing the contents of the first function.
    :
    : One argument of the first function I am given a pointer to the structure. I wish to pass the array (member of structure) to the second function. I am also passing a 3D array to the second function which I declared itself.
    :
    : typdef struct tagTimedLevel
    : {
    : ...
    : unsigned char waveform[2][1024];
    : ...
    : } TimedLevel;
    :
    : void function2(unsigned char wf[][1024], signed char sp[][2][1024])
    : {
    : ...
    : sp[0][0][0] = wf[0][0]; \ example use of elements.
    : ...
    : }
    :
    : int function1(... Timedlevel* pLevel ...)
    : {
    : signed char Spect[2][2][1024];
    : ...
    : function2(pLevel1->waveform,Spect); // I get error here.
    : ...
    : }
    :
    :
    : When I compile, I get an error 68: cannot convert parameter 1 from 'unsigned char [2][1024]' to 'unsigned char *[][1024]'
    :
    : I get no error for parameter 2.
    :
    : I get same results if I declare function2 with "2" in each empty bracket pair.
    :
    :
    :
    The spelling error I see is that you are using pLevel1 instead of pLevel in the function call. If your source code is different than what you posted, you should copy and paste it here to avoid such discrepencies. In fact, I don't see any problem with the code as you posted it (other than the above-mentioned spelling error). Perhaps there is a problem with some code you haven't posted here. Are both of these functions in the same source .cpp file. If not, do you have prototypes of each function in a header file (either the same one or two separate ones)? Please also copy and paste this prototype. I suspect the parameter order may be reversed.
  • : The spelling error I see is that you are using pLevel1 instead of pLevel in the function call. If your source code is different than what you posted, you should copy and paste it here to avoid such discrepencies. In fact, I don't see any problem with the code as you posted it (other than the above-mentioned spelling error). Perhaps there is a problem with some code you haven't posted here. Are both of these functions in the same source .cpp file. If not, do you have prototypes of each function in a header file (either the same one or two separate ones)? Please also copy and paste this prototype. I suspect the parameter order may be reversed.

    Here is excerpts of my code:

    In "Effects.h":

    typedef struct tagTimedLevel
    {
    unsigned char frequency[ 2 ][ 1024 ];
    unsigned char waveform[ 2 ][ 1024 ];
    int state;
    hyper timeStamp;
    } TimedLevel;

    using namespace std;

    In "fourier.h":

    class CFourier
    {
    ...
    public:
    ...
    int channels;
    CFourier();
    ~CFourier();
    void Transform (unsigned char wf[][1024], signed char sp[][2][1024]);
    void Inverse (unsigned char wf[][1024], signed char sp[][2][1024]);
    };

    In "fourier.cpp":

    void CFourier::Transform(unsigned char wf[][1024], signed char sp[][2][1024])
    {
    ...
    av[k] += c * circle[ix]; }
    ...
    sp[k][0][i] = av[k].real/1024;
    sp[k][1][i] = av[k].imag/1024;
    ...
    }

    In "fantasia.h":

    class ATL_NO_VTABLE CFantasia :
    public CComObjectRootEx,
    public CComCoClass,
    public IDispatchImpl,
    public IWMPEvents,
    public IWMPEffects2
    {
    private:
    ...
    CFourier Fourier;
    ...
    public:
    ...
    CFantasia();
    ~CFantasia();
    ...
    public:
    ...
    STDMETHOD(Render)(TimedLevel *pLevels, HDC hdc, RECT *rc);
    ...
    };

    In "fantasia.cpp":

    STDMETHODIMP CFantasia::Render(TimedLevel *pLevels, HDC hdc, RECT *prc)
    {
    ....
    const double pi = 3.1415926535;
    signed char Spect[2][2][1024];
    //unsigned char* pWave = pLevels->waveform;
    ....
    Fourier.Transform(pLevels->waveform,Spect); // Error occurs here!
    ....
    }

    Error message:

    :VisualizationFantasia3Fantasia.cpp(68) : error C2664: 'Transform' : cannot convert parameter 1 from 'unsigned char [2][1024]' to 'unsigned char *[][1024]'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


    I can modify the CONTENTS of the "Render" function, but not the function declaration. This function will be called by another program. I am writing the "Fourier" class from scratch, and can modify any parto of it. I don't wish to pass the entire structure of "pLevels", but just the array.

    P.S. When I previes the message, the indentations don't work...


  • I've taken a good look at your code, but I don't see why you are getting that error message. It looks to me that all the types match up correctly. Of course, I'm no compiler, but I am a fairly decent programmer. At this point I'm a bit stumped. I'll be sure to let you know if I can find anything that might help.
  • [red] Just formatted previous post....[/red]
    : The spelling error I see is that you are using pLevel1 instead of pLevel in the function call. If your source code is different than what you posted, you should copy and paste it here to avoid such discrepencies. In fact, I don't see any problem with the code as you posted it (other than the above-mentioned spelling error). Perhaps there is a problem with some code you haven't posted here. Are both of these functions in the same source .cpp file. If not, do you have prototypes of each function in a header file (either the same one or two separate ones)? Please also copy and paste this prototype. I suspect the parameter order may be reversed.

    Here is excerpts of my code:

    In "Effects.h":
    [code]
    typedef struct tagTimedLevel
    {
    unsigned char frequency[ 2 ][ 1024 ];
    unsigned char waveform[ 2 ][ 1024 ];
    int state;
    hyper timeStamp;
    } TimedLevel;

    using namespace std;
    [/code]
    In "fourier.h":
    [code]
    class CFourier
    {
    ...
    public:
    ...
    int channels;
    CFourier();
    ~CFourier();
    void Transform (unsigned char wf[][1024], signed char sp[][2][1024]);
    void Inverse (unsigned char wf[][1024], signed char sp[][2][1024]);
    };
    [/code]
    In "fourier.cpp":
    [code]
    void CFourier::Transform(unsigned char wf[][1024], signed char sp[][2][1024])
    {
    ...
    av[k] += c * circle[ix]; }
    ...
    sp[k][0][i] = av[k].real/1024;
    sp[k][1][i] = av[k].imag/1024;
    ...
    }
    [/code]
    In "fantasia.h":
    [code]
    class ATL_NO_VTABLE CFantasia :
    public CComObjectRootEx,
    public CComCoClass,
    public IDispatchImpl,
    public IWMPEvents,
    public IWMPEffects2
    {
    private:
    ...
    CFourier Fourier;
    ...
    public:
    ...
    CFantasia();
    ~CFantasia();
    ...
    public:
    ...
    STDMETHOD(Render)(TimedLevel *pLevels, HDC hdc, RECT *rc);
    ...
    };
    [/code]
    In "fantasia.cpp":
    [code]
    STDMETHODIMP CFantasia::Render(TimedLevel *pLevels, HDC hdc, RECT *prc)
    {
    ....
    const double pi = 3.1415926535;
    signed char Spect[2][2][1024];
    //unsigned char* pWave = pLevels->waveform;
    ....
    Fourier.Transform(pLevels->waveform,Spect); // Error occurs here!
    ....
    }
    [/code]
    Error message:

    :VisualizationFantasia3Fantasia.cpp(68) : error C2664: 'Transform' : cannot convert parameter 1 from 'unsigned char [2][1024]' to 'unsigned char *[][1024]'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


    I can modify the CONTENTS of the "Render" function, but not the function declaration. This function will be called by another program. I am writing the "Fourier" class from scratch, and can modify any parto of it. I don't wish to pass the entire structure of "pLevels", but just the array.

    P.S. When I previes the message, the indentations don't work...
    [red]use [leftbr]code[rightbr] before your code, and [leftbr]/code[rightbr] after your code to preserve formatting[/red]

  • I noticed that some of my .cpp and .h files were in a different directory from the rest of the project. However, they were associated with the project.

    I also had copies in the correct directory, but the ones I kept editing were in the other directory.

    When I did a "save as" into the proper directory, and did a compile, it worked.

    I would assume that the compiler would pull all the associated files from whatever directories they were in, and compile them during the build. Is that not true? Or is there a bug in Visual C++ Ver. 6?


  • [b][red]This message was edited by stober at 2003-7-1 12:5:1[/red][/b][hr]
    : I noticed that some of my .cpp and .h files were in a different directory from the rest of the project. However, they were associated with the project.
    :
    : I also had copies in the correct directory, but the ones I kept editing were in the other directory.
    :
    : When I did a "save as" into the proper directory, and did a compile, it worked.
    :
    : I would assume that the compiler would pull all the associated files from whatever directories they were in, and compile them during the build. Is that not true? Or is there a bug in Visual C++ Ver. 6?
    :
    :
    :

    it will use the *.cpp file that is included in the project, but not necessarily the *.h file. The compiler first looks in the current directory (normally the project directory). If it's not there, then it looks in the directory(s) that are in the include path (Project | Settings | PreProcessor Tab | Additional Include Directories. It will NOT use the *.h file that you have included in the project unless it also happens to be in the presiously mentioned directory(s). So if a *.h file is located somewhere else, the compiler will ignore it altogether.



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories