OOP Problem

Bit of a newbie to OOP but here's the problem:

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
#include "Tree.h"
#include "time.h"

// Constructor
Tree::Tree(int startBranches, int startLeaves, float startHeight):
                branches (startBranches),
                leaves (startLeaves),
                height (startHeight)
// Methods
void Tree::growBranch()
{
     branches++;
     cout << "The tree has " << branches << " branches";    
}

void Tree::growLeaves()
{
     
     cout << "The tree has " << leaves << "leaves";    
}

void Tree::growHeight()
{
     height++;
     cout << "The height of the tree is " << height << " feet tall";    
}


I am attempting to make a simple console based program for learning purposes.

However, I get the following compile error:

 " expected `{' before "void" " 

javascript:PostPreview()
Any ideas on how to get around this/an explanation?

Thanks.
I think you forgot braces (the body) in the constructor

Tree::Tree(int startBranches, int startLeaves, float startHeight):
branches (startBranches),
leaves (startLeaves),
height (startHeight) {}
It worked, great! Thank you! Why do the curly braces have to be in the constructor?
Because a constructor needs a body.
Right. A constructor is just like any function. All functions need a body.
Topic archived. No new replies allowed.