【发布时间】:2014-05-12 19:08:56
【问题描述】:
我的函数调用有问题
static classname *makeclass ( char ch, int x1, int y1, int x2, int y2){
cin >> ch >> x1 >> y1 >> x2 >> y2;
Ship **ptr = 0;
if ( ch != 'A' || ch != 'B' || ch != 'C' || ch != 'D'){
throw invalid_argument ("Error : invalid character input ");
}
else if ( ch == 'A'){
classname **ptr = new derivedclassname*[5];
for ( int i = 0 ; i < 5; i++){
ptr[i] = new derivedclass (x1,y1,x2,y2);
}
return *ptr;
}
return *ptr;
}
在我的主文件中:
main () {
classname *p = classname::*makeclass ( x1,y1,x2,y2);
}
我的错误:
Ship.cpp:81:14: warning: ‘classname* makeclass(char, int, int, int, int)’ defined but not used [-Wunused-function]
static classname *makeclass ( char ch, int x1, int y1, int x2, int y2){
^
/tmp/cc1eUoXA.o: In function `main':
testclass.cpp:(.text+0xc1): undefined reference to `classname::makeclass(char, int, int, int, int)'
【问题讨论】:
-
尽管语法存在各种问题,但为什么要将参数传递给
makeclass函数,因为它们是按值传递并由cin内的调用填充的? -
static看起来不对,除非你在类声明中有这个内联!否则,链接器只会看到它在其中定义的编译单元的私有。
标签: c++ static function-calls