我尝试为线路创建构造函数,但我仍然遇到此错误,即使这在poolball类上运行并且能够在添加line.cpp和line.h之前运行。此外,这是来自类的代码,我不知道它为什么不编译。
#include "Line.h"
Line::Line(){
}
Line::Line( int x1, int y1, int x2, int y2){
}
void Line::setPos(int x1, int y1, int x2, int y2){
}
void Line::draw( void ){
}
-------------------------------------------------------------------------
#pragma once
class Line{
public:
int x1;
int y1;
int x2, y2;
//constructor
Line();
Line( int x1, int y1, int x2, int y2);
//methods
void setPos(int x1, int y1, int x2, int y2);
void draw( void);
这是我在尝试构建和运行时遇到的错误
||=== Build: Debug in 10.19class (compiler: GNU GCC Compiler) ===|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|2|error: extra qualification 'Line::' on member 'Line' [-fpermissive]|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|2|error: 'Line::Line()' cannot be overloaded|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.h|10|error: with 'Line::Line()'|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|5|error: extra qualification 'Line::' on member 'Line' [-fpermissive]|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|5|error: 'Line::Line(int, int, int, int)' cannot be overloaded|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.h|11|error: with 'Line::Line(int, int, int, int)'|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|9|error: extra qualification 'Line::' on member 'setPos' [-fpermissive]|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|9|error: 'void Line::setPos(int, int, int, int)' cannot be overloaded|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.h|13|error: with 'void Line::setPos(int, int, int, int)'|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|12|error: extra qualification 'Line::' on member 'draw' [-fpermissive]|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|12|error: 'void Line::draw()' cannot be overloaded|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.h|14|error: with 'void Line::draw()'|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|13|error: expected '}' at end of input|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp||In constructor 'Line::Line(int, int, int, int)':|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|6|error: 'cout' is not a member of 'std'|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|6|error: 'endl' was not declared in this scope|
C:\Users\Admin\Desktop\C++Projects\10.19class\Line.cpp|13|error: expected unqualified-id at end of input|
||=== Build failed: 16 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
答案 0 :(得分:0)
void Line(void)
不正确,构造函数没有返回类型,在参数列表中也不应该写void
。
答案 1 :(得分:0)
根据错误消息判断,并假设破折号下方的内容是您的头文件的完整内容,那么您的问题是您在头文件的末尾缺少someService.arrayVal
。您需要在标题中使用小括号和分号关闭类定义,然后才能在Line.cpp文件中实现这些函数。