小编jvp*_*nis的帖子

定义未命名的类成员函数?

我目前在 Foo.h 中定义了两个未命名的类:

class Foo {
public:
    Foo();

    class {
    private:
        int x;
        int y;
    public:
        int GetX() { return x; }
        int GetY() { return y; }
    } Sub1;

    class {
    private:
        int x;
    public:
        int GetX() { return x; }
    } Sub2;
}
Run Code Online (Sandbox Code Playgroud)

这段代码编译得很好,它是这样使用的:

 Foo temp;
 int Ax, Ay, Bx;
 Ax = temp.Sub1.GetX();
 Ay = temp.Sub1.GetY();
 Bx = temp.Sub2.GetX();
Run Code Online (Sandbox Code Playgroud)

但是,现在我想将成员函数定义移动到源文件中。我知道将此类拆分为头文件和源文件的唯一方法是命名这些类:

福.h:

class Foo {

private:    
    class A {
    private:
        int x;
        int y;
    public:
        int GetX();
        int GetY(); …
Run Code Online (Sandbox Code Playgroud)

c++ class definition member-functions

6
推荐指数
1
解决办法
440
查看次数

标签 统计

c++ ×1

class ×1

definition ×1

member-functions ×1