C++ forbids declaration of ‘setPosition’ with no type

Hi all.

Trying to work through exercises in "An Introduction to design Patterns in C++ with QT". Simple, trivial stuff but I've been beating my head for a week trying to get past this.

There are three classes - Person, Employer and Position - and the Work main. Here's the code (most of the 'offending' lines are commented out trying to track down the cause):

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
======================================
#ifndef _PERSON_H_ 
#define _PERSON_H_  

#include <QString>

class Employer;
class Position;

class Person
{

  public:
  
    Person(QString name);
    //setPosition(Employer newC, Position newP);
    setPosition(Employer newC);
    QString toString();

  private:
    
    QString m_Name;
    bool m_Employed;
    //Position m_Position;
    //Employer m_Employer;

};

#endif

=========================================

// Person.cpp
// pn Mar03-2014

#include <QString>
#include <QTextStream>
#include "position.h"
#include "person.h"
#include "employer.h"


Person::Person(QString name)
  : m_Name(name)
{
  
}

QString Person::toString()
{
  QString buffer;
  QTextStream bufStr(&buffer);
  bufStr << "Person Name: " << m_Name << endl;
  //buffer = "Person Name: " + m_Name + "\n";
  return buffer;
}

/*
Person::setPosition(Employer newC, Position newP)
{
  m_Position = newP;
  m_Employer = newC;
}
*/

=====================================

#ifndef _EMPLOYER_H_ 
#define _EMPLOYER_H_  

#include <QString>

class Person;
//class Position;


class Employer
{

  public:
    Employer(QString name, QString market);
    // bool hire(Person& newHire, Position pos);
    QString toString();

  private:
    
    QString m_Name;
    QString m_Market;

};

#endif

==========================================

// employer.cpp
// pn Mar05-2014

#include <QString>
#include <QTextStream>
#include "position.h"
#include "person.h"
#include "employer.h"

Employer::Employer(QString name, QString market)
  : m_Name(name), m_Market(market)
{
  
}

QString Employer::toString()
{
  QString buffer;
  QTextStream bufStr(&buffer);
  bufStr << "Employer Name: " << m_Name << endl;
  bufStr << "Employer Market: " << m_Market << endl;
  //buffer = "Person Name: " + m_Name + "\n";
  //return buffer.toStdString();
  return buffer;  //QString
}

/*
bool Employer::hire(Person& newHire, Position pos)
{
  return true; 
}
*/

====================================

#ifndef _POSITION_H_ 
#define _POSITION_H_  

#include <QString>

class Employer;
class Person;

class Position
{

  public:
    Position(QString name, QString description);
    QString toString();

  private:
    
    QString m_Name;
    QString m_Description;

};

#endif

=====================================

// Position.cpp
// pn Mar03-2014

#include <QString>
#include <QTextStream>
#include "position.h"
#include "person.h"
#include "employer.h"

Position::Position(QString name, QString description)
  : m_Name(name), m_Description(description)
{
  
}

QString Position::toString()
{
  QString buffer;
  QTextStream bufStr(&buffer);
  bufStr << "Position Name: " << m_Name << endl;
  bufStr << "Position Description: " << m_Description << endl;
  //buffer = "Position Name: " + m_Name + "\n";
  //return buffer.toStdString();
  return buffer;
}

=========================================

// work.cpp
// pn mar05-2014

#include <QString>
#include <QTextStream>
#include <iostream>
#include "person.h"
#include "employer.h"
#include "position.h"

using namespace std;

int main()
{

  QString name;
  QString company;
  QString location;
  Person phil("Bozo");
  Employer sst("SST", "Speed");
  Position posture("Standing", "Not Sitting");
  //QTextStream qts();
  //qts << phil.toString();
  name = phil.toString();
  cout << name.toStdString();
  company = sst.toString();
  cout << company.toStdString();
  location = posture.toString();
  cout << location.toStdString();
  
  return 0;
  
}

======================================


Any ideas?

TIA
/*type*/ setPosition(Employer newC); setPosition needs a return type.
Last edited on
You've got to be kidding me. I thought of that, but then though 'naahh'. I gave it a void and it compiled. Do you know why it needs a return type? I haven't defined it with a return type. The function definition is actually commented out so it's not even defined at all.

Anyway, thanks very much.

ps How do I mark this solved?
Do you know why it needs a return type?

The language requires it. All functions must have a return type.
Topic archived. No new replies allowed.