小编acl*_*ark的帖子

从另一个方法调用非静态成员方法

有没有办法从c ++主类中包含的另一个方法调用非静态类成员方法?如果是这样,代码会是什么样的?

问题是,我不能将这个specfic方法声明为static,因为它使用同一个类中的其他方法,如果我将其静态化,则不起作用.

我正在尝试使用:

MyClass::myClassMethod();
Run Code Online (Sandbox Code Playgroud)

从主类中的方法,但它给我错误:非静态成员引用必须相对于特定对象.

为了澄清,myClassMethod()使用MyClass中的其他方法,如:

void myClassMethod() {
    ...
    anotherClassMethod();
}
Run Code Online (Sandbox Code Playgroud)

因此,如果我将myClassMethod设为静态,则会干扰调用anotherClassMethod().

c++ methods static-methods class

8
推荐指数
1
解决办法
2万
查看次数

使用MS Visual Studio与GCC的结果不同

我编写了一个C程序,然后在MS Visual Studio中编译并运行它,然后使用GCC.该程序进行了一些简单的数学计算.但是我从两者得到的输出/结果是不同的.该程序基于宏.

这些编程环境是否有不同的处理宏的方式?如果是这样,有什么区别?

编辑:对不起,这是代码.

#include <stdio.h>
#define mac(a,b) a*a + b*b - 2*a*b

int func(int a, int b) {
    return (a*a + b*b - 2*a*b);
}
main() {
    int f, g, i, j, x, y;
    printf("Please enter two integers\n");
    scanf("%d%d", &f, &g);
    printf("f = %d\tg = %d\n", f, g);
    i = f;
    j = g;
    x = func(i, j);
    y = mac(i, j);
    printf("x = %d\ty = %d\n", x, y);
    x = func(++i, ++j);
    i = f;
    j = …
Run Code Online (Sandbox Code Playgroud)

c gcc visual-studio-2008

-3
推荐指数
1
解决办法
3308
查看次数

标签 统计

c ×1

c++ ×1

class ×1

gcc ×1

methods ×1

static-methods ×1

visual-studio-2008 ×1