I'm learning cpp by myself and get stuck on classes. I have read some stuff on this forum and my cpp book, but still didn't figure out where is the problem.
//klasy.h
#ifndef KLASY_H
#define KLASY_H
class Submarine
{
public:
Submarine(int = 0, int = 0, int = 0, int = 0);
private:
int id_area;
int speed_max;
int speed_left;
int range;
public:
void resetSpeed();
void setMaxSpeed(int);
void moveToArea(int);
};
#endif
When im trying to compile it:
$ g++ -o main2 main2.cpp
machine says:
/tmp/ccmIhNGI.o: In function `main':
main2.cpp:(.text+0x31): undefined reference to `Submarine::Submarine(int, int, int, int)'
collect2: error: ld returned 1 exit status
$ g++ -o main2 main2.cpp klasy.cpp
klasy.cpp:6:34: error: expected ‘,’ or ‘...’ before numeric constant
klasy.cpp:6:1: error: prototype for ‘Submarine::Submarine(int, int)’ does not match any in class ‘Submarine’
In file included from klasy.cpp:4:0:
klasy.h:5:7: error: candidates are: Submarine::Submarine(const Submarine&)
klasy.h:8:1: error: Submarine::Submarine(int, int, int, int)
klasy.cpp:17:35: error: declaration of ‘void Submarine::setMaxSpeed(int)’ outside of class is not definition [-fpermissive]
klasy.cpp:18:1: error: expected unqualified-id before ‘{’ token
$ g++ -o main2 main2.cpp klasy.cpp
klasy.cpp:6:34: error: expected ‘,’ or ‘...’ before numeric constant
klasy.cpp:6:1: error: prototype for ‘Submarine::Submarine(int, int)’ does not match any in class ‘Submarine’
In file included from klasy.cpp:4:0:
klasy.h:5:7: error: candidates are: Submarine::Submarine(const Submarine&)
klasy.h:8:1: error: Submarine::Submarine(int, int, int, int)
//klasy.h
#ifndef KLASY_H
#define KLASY_H
class Submarine
{
public:
Submarine(int = 0, int = 0, int = 0, int = 0);
private:
int id_area;
int speed_max;
int speed_left;
int range;
public:
void resetSpeed();
void setMaxSpeed(int);
void moveToArea(int);
};
#endif