首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于函数访问的有关问题

2012-12-28 
关于函数访问的问题我在做函数访问的测试,但是出现了很多问题,请帮我改正一下,谢谢!:\我的\学习\编程\c++\

关于函数访问的问题
我在做函数访问的测试,但是出现了很多问题,请帮我改正一下,谢谢!
:\我的\学习\编程\c++\chapter4\fw.cpp(17) : error C2143: syntax error : missing ';' before '.'
C:\我的\学习\编程\c++\chapter4\fw.cpp(17) : error C2143: syntax error : missing ';' before '.'
C:\我的\学习\编程\c++\chapter4\fw.cpp(18) : error C2248: 'func1' : cannot access private member declared in class 't'
        C:\我的\学习\编程\c++\chapter4\fw.cpp(5) : see declaration of 'func1'
C:\我的\学习\编程\c++\chapter4\fw.cpp(19) : error C2248: 'func2' : cannot access private member declared in class 't'
        C:\我的\学习\编程\c++\chapter4\fw.cpp(6) : see declaration of 'func2'
C:\我的\学习\编程\c++\chapter4\fw.cpp(20) : error C2248: 'func1' : cannot access private member declared in class 't'
        C:\我的\学习\编程\c++\chapter4\fw.cpp(5) : see declaration of 'func1'
C:\我的\学习\编程\c++\chapter4\fw.cpp(21) : error C2248: 'func2' : cannot access private member declared in class 't'
        C:\我的\学习\编程\c++\chapter4\fw.cpp(6) : see declaration of 'func2'
执行 cl.exe 时出错.

fw.obj - 1 error(s), 0 warning(s)


#include "iostream.h"
class t{
char t1;
static char t2;
void func1();
static void func2();
};
void func1(){
cout<<"this is func1"<<endl;
}
void func2(){
cout<<"this is func2"<<endl;
}
void main(){
t s1,s2;
//t.func1();
t.func2();
s1.func1();
s1.func2();
    s2.func1();
s2.func2();
}
[最优解释]

#include "iostream"
using namespace std;
class t{
public:
char t1;
static char t2;
void func1();
static void func2();
};
void func1(){
cout<<"this is func1"<<endl;
}
void func2(){
cout<<"this is func2"<<endl;
}
void main(){
t s1,s2;
//t.func1();
t::func2();

s1.func1();
s1.func2();
s2.func1();
s2.func2();
}
 
[其他解释]

改下
#include "iostream"
using namespace std;
class t{
public:
char t1;
static char t2;
void func1();
static void func2();
};
void t::func1(){
cout<<"this is func1"<<endl;
}
void  t::func2(){
cout<<"this is func2"<<endl;
}
void main(){
t s1,s2;
//t.func1();
t::func2();

s1.func1();
s1.func2();
s2.func1();
s2.func2();
}
 
[其他解释]
引用:
改下


C/C++ code
?



12345678910111213141516171819202122232425

#include "iostream" using namespace std; class t{ public:     char t1;     static char t2;     void func1();     static void f……







void main(){
t s1,s2;
//t.func1();
t.func2();
s1.func1();
s1.func2();
    s2.func1();
s2.func2();
}
改了之后,这个错误是怎么回事啊
rror C2143: syntax error : missing ';' before '.'
[其他解释]
引用:
改下


C/C++ code
?



12345678910111213141516171819202122232425

#include "iostream" using namespace std; class t{ public:     char t1;     static char t2;     void func1();     static void f……



我把其中一行改了://t.func2();就能运行了,但是,按理说,t应该可以访问静态函数啊
[其他解释]
引用:
改下


C/C++ code
?



12345678910111213141516171819202122232425

#include "iostream" using namespace std; class t{ public:     char t1;     static char t2;     void func1();     static void f……

额,我看漏了,嘿嘿,谢啦!

热点排行