如何在C ++类中调用方法 [英] How to call a method in class C++

查看:364
本文介绍了如何在C ++类中调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C ++构建了一个Windows窗体应用程序,然后用方法创建了一个类。但是当访问这些方法时它不起作用。我已经包含头文件以及那些方法是公共的。请帮我解决这个问题。



这是方法。



I have built a windows form application in C++ and I created a class with methods. But when accessing those methods it doesn''t work.I have included header files as well as those methods are public. Please help me with this problem.

Here is the method.

int Segmentation::Vertical_Projection(char *filename,int width,int height){...}



这是在Segmentation.cpp中我的班级名称是Segmentation。




This is inside Segmentation.cpp and my class name is Segmentation.

class Segmentation
{
public:
    Segmentation(void);
    ~Segmentation(void);

    IplImage* Resize(IplImage *img);
    char Horizontal_projection(int width,int height,IplImage *binary,int countPositions,int *pos);
    int Vertical_Projection(char *filename,int width,int height);
};



这是在Segmentation.h内部



我试图访问该方法在包含头文件的另一个源文件中。


This is inside Segmentation.h

I was trying to access that method in another source file with including the header file.

推荐答案

此方法是实例方法,而不是静态方法。你不能这样称呼它。您应首先使用 gcnew 创建 Segmentation ^ myInstance 的实例,然后通过<$ c $使用此实例调用它c> myInstance-> Vertical_Projection(/ * ... * /):

This method is an instance method, not a static method. You cannot call it like this. You should first make an instance of Segmentation^ myInstance using gcnew and then call it with this instance via myInstance->Vertical_Projection(/* ... */):
Segmentation^ myInstance = gcnew Segmentation();
myInstance->Vertical_Projection(/* ... */);





请参阅: http://msdn.microsoft.com/en-us/library/te3ecsc8%28v=vs.110%29.aspx [ ^ ]。



让我告诉你,遗憾的是,没有任何答案可以帮助你完成任何编程:此时此刻,你没有任何线索。这是一个基本的东西,你真的应该从一开始就开始。拿一本书或一本手册,从一开始就做,尽可能做最简单的练习。如果您有信心,请回来询问您的问题。



-SA


这篇关于如何在C ++类中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆