Copy Constructor Exercise Problem

I'm getting these errors and don't quite know what to do with them. As far as I've seen (though I've been coding for about 7 hours straight now, so issues could be evading me) the code is the same as the code in the book I'm following.

thanks!

errors:

deepcopy.cpp:18:19: error: ISO C++ forbids declaration of ‘Tricyle’ with no type [-fpermissive]
deepcopy.cpp:18:19: error: no ‘int Tricycle::Tricyle()’ member function declared in class ‘Tricycle’
deepcopy.cpp: In function ‘int main()’:
deepcopy.cpp:56:57: error: invalid operands of types ‘int’ and ‘const char [2]’ to binary ‘operator<<’



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>

class Tricycle
{
public: 
	Tricycle();
	Tricycle(const Tricycle&);
	~Tricycle();
	int getSpeed() const { return *speed; }
	void setSpeed(int newSpeed) { *speed = newSpeed ; }
	void pedal();
	void brake();

private:
	int *speed;
};

Tricycle::Tricyle()
{
	speed = new int;
	*speed = 5;
}

Tricycle::Tricycle(const Tricycle& rhs)
{
	speed = new int;
	*speed = rhs.getSpeed();
}

Tricycle::~Tricycle()
{
	delete speed;
	speed = NULL;
}

void Tricycle::pedal()
{
	setSpeed(*speed + 1);
	std::cout << "\nPedaling " << getSpeed() << " mph\n";
}

void Tricycle::brake()
{
	setSpeed(*speed - 1);
	std::cout << "\nPedaling " << getSpeed() << " mph\n";
}

int main()
{
	std::cout << "Creating trike named wichita ... ";
	Tricycle wichita;
	wichita.pedal();
	std::cout << "Creating trike named dallas ... \n";
	Tricycle dallas(wichita);
	std::cout << "Wichita's speed: " << wichita.getSpeed() << "\n";
	std::cout << "dallas's speed: " < dallas.getSpeed() << "\n";
	std::cout << "setting wichita to 10 .. \n";
	wichita.setSpeed(10);
	std::cout << "wichita's speed: " << wichita.getSpeed() << "\n";
	std::cout << "dallas's speed: " << dallas.getSpeed() << "\n";
	return 0;
}
1) You mistyped Tricycle after the :: in your constructor definition.
2) You mistyped << on that line.
sigh, it always seems to be simple typos >.<

thank you :)
Topic archived. No new replies allowed.