关于函数访问的问题
我在做函数访问的测试,但是出现了很多问题,请帮我改正一下,谢谢!
:\我的\学习\编程\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();
}