静态成员帮助 [英] static members help

查看:69
本文介绍了静态成员帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我收到此错误


/tmp/ccYZ9ROC.o(.text+0x139):在函数`temp :: init()''中:

:未定义引用`temp :: array''

/tmp/ccYZ9ROC.o(.text+0x157):函数`temp :: setArray()'':

:未定义引用`temp :: array''

/tmp/ccYZ9ROC.o(.text+0x19a):在函数`temp :: print()''中:

:未定义引用`temp :: array''

collect2:ld返回1退出状态

这里是我的代码:


#include< iostream>

使用命名空间std;


class temp

{

public:

void init();

void setArray();

void print(); <私人:

静态字符数组[3] [3];

int row,col;

};


void temp :: init()

{

for(row = 0; row< 3; row ++){

for(col = 0; col< 3; col ++){


temp :: array [row] [col] =' ''';

}

}

}


void temp :: setArray()

{

temp :: array [0] [0] =''P'';

}

void temp :: print()

{

for(row = 0;行< 3;行++){

for(col = 0; col< 3; col ++){


cout<< array [row] [col]<< endl;

}

}


}

int main()

{

temp t;

t.init();

t。 setArray();

t.print();

}


提前谢谢。

推荐答案

reddy写道:
嗨我收到此错误

/tmp/ccYZ9ROC.o( .text + 0x139):在函数`temp :: init()''中:
:未定义引用`temp :: array''
/tmp/ccYZ9ROC.o(.text+0x157):函数`temp :: setArray()'':
:未定义引用`temp :: array''
/tmp/ccYZ9ROC.o(.text+0x19a):函数`temp :: print()'':
:未定义引用`temp :: array''
collect2:ld返回1退出状态

这里是我的代码:

#include< iostream>
使用命名空间std;

类temp
{
公开:
void init();
void setArray();
void print();
private:
static char array [3] [3];


这是声明。定义在哪里?

int row,col;
};
[...]
hi I am getting this error

/tmp/ccYZ9ROC.o(.text+0x139): In function `temp::init()'':
: undefined reference to `temp::array''
/tmp/ccYZ9ROC.o(.text+0x157): In function `temp::setArray()'':
: undefined reference to `temp::array''
/tmp/ccYZ9ROC.o(.text+0x19a): In function `temp::print()'':
: undefined reference to `temp::array''
collect2: ld returned 1 exit status
here is my code:

#include <iostream>
using namespace std;

class temp
{
public:
void init();
void setArray();
void print();
private:
static char array[3][3];
This is the declaration. Where is the definition?
int row , col;
};
[...]




V



V


我已经在init中定义了它..


但是如何让这个程序运行...


谢谢。

i have defined it in init right..

but how to make this program run...

thank you.


reddy写道:
我已经定义了初衷吧..

但是如何让这个程序运行...
i have defined it in init right..

but how to make this program run...




我想你不明白这些术语声明"," definition",

以及它们之间的区别。再次阅读您的书,关于静态数据成员的部分

。顺便说一下,你在C ++上读什么书?


V



I guess you don''t understand the terms "declaration", "definition",
and the difference between them. Read your book again, the section
about static data members. BTW, what book are you reading on C++?

V


这篇关于静态成员帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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