Daniel Oloughiln
Daniel Oloughiln

Reputation: 3

How can I pass a c++ object as a parameter to function?

I've got three classes in a project I'm working on called Pixel, custFrame, and FrameHolder.

My custFrame class header is like so:

#pragma once
#include "stdafx.h"
#include <gl/gl.h>
#include "PreviewWindow.h"
#include <iostream>
#include <sstream>
#include <vector>
#include "FrameHolder.h"
#include "Pixel.h"
#ifndef CUSTFRAME_H
#define CUSTFRAME_H
class custFrame
{
public:
    custFrame();
    void addPixel(Pixel pix);
    void setWidth(int width);
    void setHeight(int height);
    int getWidth();
    int getHeight();
    int getPixelSize();
    Pixel getPixel(int count);
private:
    std::vector<Pixel> pixels;
    int Height;
    int Width;
};
#endif

and my FrameHolder class header is like so:

#pragma once
//Hold all captured frames containing data

#include "stdafx.h"
#include <gl/gl.h>
#include "PreviewWindow.h"
#include <iostream>
#include <sstream>
#include <vector>
#include "FrameHolder.h"
#include "custFrame.h"
#include "Pixel.h"

#ifndef FRAMEHOLDER_H
#define FRAMEHOLDER_H

class FrameHolder {

public:
    FrameHolder();
    static FrameHolder* instance();

    void addFrame(IDeckLinkVideoFrame* fram);
    void calibrate(custFrame fram);
    int numFrames();
    void setWidth(int width);
    void setHeight(int height);
    static FrameHolder *inst;
    bool calibrating;
    int getHeight();
    int getWidth();
    bool isCalibrating();

private:
    //Member variables
    int Width;
    int Height;
    std::vector<IDeckLinkVideoFrame *>frames;

};

#endif

In my FrameHolder class passing a custFrame object to a function to store that frame in the object does not seem to work. I get a compiler error ("syntax error: identifier 'custFrame' line 24"). However in my custFrame class, passing a Pixel object to be stored as part of a frame works wonderfully. Am I missing something? I've seen this post but it didn't help much.

Upvotes: 0

Views: 102

Answers (2)

R Sahu
R Sahu

Reputation: 206737

The problem is caused by the presence of

#include "FrameHolder.h"

in both the .h files. Because of that, the definition of custFrame is not seen before the definition of FrameHolder.

Upvotes: 1

Untitled123
Untitled123

Reputation: 1293

Passing by pointers/references is probably what you should be doing here. As for the syntax error, it might be that the custFrame class is not declared properly when you include it in the header.

Upvotes: 0

Related Questions