如何将c++对象作为参数传递给函数
How can I pass a c++ object as a parameter to function?
我在一个项目中有三个类,分别叫Pixel、custFrame和FrameHolder。
我的custFrame类标题是这样的:
#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
我的FrameHolder类标题是这样的:
#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
在我的FrameHolder类中,将custFrame对象传递给函数以将该帧存储在对象中似乎不起作用。我得到一个编译器错误("语法错误:标识符'custFrame'第24行")。然而,在我的custFrame类中,传递一个Pixel对象作为帧的一部分进行存储非常有效。我是不是错过了什么?我看过这篇文章,但没有多大帮助。
问题是由的存在引起的
#include "FrameHolder.h"
在两个.h文件中。因此,custFrame
的定义在FrameHolder
的定义之前是看不到的。
通过指针/引用传递可能是您在这里应该做的事情。至于语法错误,可能是在头中包含custFrame类时,它没有正确声明。
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 使用指向成员的指针将成员函数作为参数传递
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 修改函数中的指针(将另一个指针作为参数传递)
- 将成员函数指针作为参数传递给模板方法
- 如何在C++中将迭代器作为函数参数传递
- 将附加参数传递给使用 beast::bind_front_handler 调用的函数
- 如何将一个类的函数作为另一个类的另一个函数的参数传递
- 如何传递带有通过引用传递的结构参数的函数?
- 如何在 c++ 中将函数作为参数传递?
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 将参数打包的参数传递到 std::queue 中,以便稍后使用不同的函数调用
- 为什么我不能将引用作为 std::async 的函数参数传递
- 如何在不使用指针的情况下将派生类的对象作为参数传递给基类中的函数?
- 将__device__ lambda 作为参数传递给 __global__ 函数
- 是否可以在不填充自己的参数的情况下将模板函数作为参数传递?
- 如何将成员函数作为参数传递并在派生对象上执行方法列表
- 将函数作为参数传递以避免重复代码
- 如何在类(C )中作为参数传递函数