error 2039 in my code although the function is declared

hello everyone,
first, i'm writing a C++ client for at least myself for [url=https://wit.ai]wit.ai[/url] using jsoncpp and libcurl
but, i have some problems:
1. i want to test that libcurl is working or not, so i've wrote this C++ file (made using vs wizard):
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
// wit.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "witpp.h"

using namespace std;
using namespace witpp;

int main()
{
try
{
MessageRequest m;
Parameter p;
p.setAuth("server_token");
MessageResponce r=m.setParameter(p).setMessage("this is a test message").perform();
cout<<"message id: "<<r.getMessageId()<<" message: "<<r.getText();
}
catch(WitException& e)
{
cerr<<e.what();
exit(1);
}
    return 0;
}

and here is the header:
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#ifndef _WITPP_H
#define _WITPP_H
#pragma once

//include the headers
#include <ctime>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <json/json.h>
#include <curl/curl.h>

namespace witpp
{

//this callback function gets called when a data is going to be received
size_t writecb(char* buf, size_t sz, size_t items, void* ud)
{
std::string buffer=reinterpret_cast<char*>(ud);
buffer.clear();
buffer.append(buf, sz*items);
return sz*items;
}

//this class holds the parameters like authorization, version, etc
class Parameter
{
std::string version;
std::string server_token;
public:
Parameter()
{
time_t t=time(0);
struct tm n=*localtime(&t);
char buf[80];
strftime(buf, sizeof(buf), "%Y%m%d", &n);
version=buf;
}

Parameter& setVersion(std::string v)
{
version=v;
return *this;
}

std::string getVersion()
{
return version;
}

Parameter& setAuth(std::string auth)
{
server_token=auth;
return *this;
}

std::string getAuth()
{
return server_token;
}

};

//this class is an exception for wit.ai
class WitException: public std::exception
{
std::string errorText;
int errorCode;
public:
WitException(std::string e, int c):
errorText(e),
errorCode(c)
{

}

const char* what()
{
return errorText.c_str();
}

int getCode()
{
return errorCode;
}

};

//this class represents a responce which the request return's it
class Responce
{
protected:
Json::Value responce;
public:
Responce(std::string r)
{
Json::Reader reader;
if(!reader.parse(r, responce, true))
{
throw std::invalid_argument(reader.getFormatedErrorMessages());
}
if(responce.isMember("error")||responce.isMember("code"))
{
throw WitException(responce["error"].asString(), responce["code"].asInt());;
}
}

};

//this class is derived from Responce that shows a message (for MessageRequest and Speech Request)
class MessageResponce: public Responce
{
public:

MessageResponce(std::string s):
Responce(s)
{

}

std::string getMessageId()
{
return responce["msg_id"].asString();
}

std::string getText()
{
return responce["_text"].asString();
}

Json::Value& getEntities()
{
return responce["entities"];
}

};

//this class represents a request
class Request
{
protected:
CURL* c;
struct curl_slist* headers;
std::string host;
Parameter param;

Request()
{
host="https://api.wit.ai/";
c=curl_easy_init();
headers=curl_slist_append(nullptr, "Content-Type: application/json");
headers=curl_slist_append(headers, "Accept: application/json");
}

~Request()
{
curl_slist_free_all(headers);
curl_easy_cleanup(c);
}

Request& setHost(std::string h)
{
host=h;
return *this;
}

std::string getHost()
{
return host;
}

public:
Request& setParameter(Parameter& p)
{
param=p;
return *this;
}

Parameter& getParameter()
{
return param;
}

virtual Responce& perform()=0;

};

//this class is a request for message
class MessageRequest: public Request
{
CURLcode res;
std::string thread_id;
std::string message_id;
std::string message;
Context context;
bool has_context;
int n_best;
bool verbose;
public:
MessageRequest():
Request()
{
setHost(getHost()+"message");
has_context=false;
n_best=1;
}

MessageRequest& setMessage(std::string m)
{
message=m;
return *this;
}

std::string getMessage()
{
return message;
}

MessageRequest& setMessageId(std::string id)
{
message_id=id;
return *this;
}

std::string getMessageId()
{
return message_id;
}

MessageRequest& setThreadId(std::string id)
{
thread_id=id;
return *this;
}

std::string getThreadId()
{
return thread_id;
}

MessageRequest& setContext(Context c)
{
context=c;
has_context=true;
}

Context& getContext()
{
return context;
}

MessageRequest& setNBest(int n)
{
n_best=n;
return *this;
}

int getNBest()
{
return n_best;
}

MessageRequest&setVerbose(bool v)
{
verbose=v;
}

bool getVerbose()
{
return verbose;
}

Responce& perform()
{
std::string s=host+"?v="+param.getVersion();
if(has_context)
{
s+="&context="+(std::string)context;
}
if(message_id!="")
{
s+="&msg_id="+message_id;
}
if(thread_id!="")
{
s+="&thread_id="+thread_id;
}
s+="&n="+n_best;
s+="&verbose="+verbose?"1":"0";
std::string token_header="Authorization: Bearer "+param.getAuth();
headers=curl_slist_append(headers, token_header.c_str());
char*esc=curl_escape(s.c_str(), s.length());
s=esc;
res=curl_easy_setopt(c, CURLOPT_URL, s.c_str());
if(res!=0)
{
throw WitException((std::string)curl_easy_strerror(res), res);
}
res=curl_easy_setopt(c, CURLOPT_HTTPHEADER, headers);
if(res!=0)
{
throw WitException((std::string)curl_easy_strerror(res), res);
}
res=curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, writecb);
if(res!=0)
{
throw WitException((std::string)curl_easy_strerror(res), res);
}
std::string data;
res=curl_easy_setopt(c, CURLOPT_WRITEDATA, &data);
if(res!=0)
{
throw WitException((std::string)curl_easy_strerror(res), res);
}
res=curl_easy_perform(c);
if(res!=0)
{
throw WitException((std::string)curl_easy_strerror(res), res);
}
curl_free(esc);
return MessageResponce(data);
}

};

}

#endif //_WITPP_H 

now, i'm getting this error:
1
2
3
4
5
6
7
8
9
1
1>  wit.cpp
1>c:\users\amir\documents\visual studio 2015\projects\wit test\wit\witpp.h(300): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\time.h(505): note: see declaration of 'localtime'
1>c:\users\amir\documents\visual studio 2015\projects\wit test\wit\wit.cpp(17): error C2039: 'setMessage': is not a member of 'witpp::Request'
1>  c:\users\amir\documents\visual studio 2015\projects\wit test\wit\witpp.h(406): note: see declaration of 'witpp::Request'
1>c:\users\amir\documents\visual studio 2015\projects\wit test\wit\wit.cpp(17): error C2228: left of '.perform' must have class/struct/union
1>c:\users\amir\documents\visual studio 2015\projects\wit test\wit\wit.cpp(17): error C2512: 'witpp::MessageResponce': no appropriate default constructor available
1>  c:\users\amir\documents\visual studio 2015\projects\wit test\wit\witpp.h(377): note: see declaration of 'witpp::MessageResponce'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

although MessageRequest has the function SetMessage()
here is the parts of code which was left (the context class which i didnt used that in this test):
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//this class represents a value for context
class ContextValue
{
std::string value;
std::vector <std::string> expressions;
public:
ContextValue& setValue(std::string v)
{
value=v;
return *this;
}

std::string getValue()
{
return this->value;
}

ContextValue& addExpression(std::string expression)
{
expressions.push_back(expression);
return *this;
}

std::vector<std::string>& getExpressions()
{
return expressions;
}

};

//this class represents an entity
class ContextEntity
{
std::string id;
std::vector<ContextValue> values;

public:

ContextEntity& setId(std::string i)
{
this->id=i;
return *this;
}

std::string getId()
{
return this->id;
}

ContextEntity& addValue(ContextValue& value)
{
values.push_back(value);
return *this;
}

std::vector<ContextValue>& getValues()
{
return values;
}

};

//this class represents a context
class Context
{
private:
std::vector<std::string> states;
std::string referenceTime;
std::string timezone;
std::string locale;
std::vector<ContextEntity> entities;

public:
Context()
{
states.clear();
referenceTime="";
timezone="";
locale="";
entities.clear();
}

Context(std::string s)
{
Json::Reader r;
Json::Value root;
if(!r.parse(s, root, true))
{
throw std::invalid_argument(r.getFormatedErrorMessages());
}
Json::Value st=root["state"];
if(!st.empty())
{
for(unsigned int i=0;i<st.size();i++)
{
addState(st[i].asString());
}
}
if(!root["reference_time"])
{
setReferenceTime(root["reference_time"].asString());
}
if(!root["timezone"])
{
setTimezone(root["timezone"].asString());
}
Json::Value ent=root["entities"];
if(!ent.empty())
{
for(unsigned int i=0;i<ent.size();i++)
{
ContextEntity e;
e.setId(ent[i]["id"].asString());
Json::Value vals=ent["values"];
for(unsigned int j=0;j<vals.size();j++)
{
ContextValue v;
v.setValue(vals[j]["value"].asString());
Json::Value expr=vals[j]["expressions"];
for(unsigned int exp=0;exp<expr.size();exp++)
{
v.addExpression(expr[exp].asString());
}
e.addValue(v);
}
addEntity(e);
}
}
if(!root["locale"].empty())
{
setLocale(root["locale"].asString());
}
}

operator std::string()
{
Json::FastWriter w;
Json::Value root;
if(!states.empty())
{
Json::Value st(Json::ValueType::arrayValue);
for(unsigned int i=0;i<getStates().size();i++)
{
st.append(getStates()[i]);
}
root["state"]=st;
}
if(getReferenceTime()!="")
{
root["reference_time"]=getReferenceTime();
}
if(getTimezone()!="")
{
root["timezone"]=getTimezone();
}
if(!entities.empty())
{
Json::Value v(Json::ValueType::arrayValue);
for(unsigned int i=0;i<entities.size();i++)
{
Json::Value vals(Json::ValueType::objectValue);
vals["id"]=entities[i].getId();
Json::Value values(Json::ValueType::arrayValue);
for(unsigned int j=0;j<entities[i].getValues().size();j++)
{
values["value"]=entities[i].getValues()[j].getValue();
Json::Value expressions(Json::ValueType::arrayValue);
for(unsigned int k=0;k<entities[i].getValues()[j].getExpressions().size();k++)
{
expressions.append(entities[i].getValues()[j].getExpressions()[k]);
}
values["expressions"]=expressions;
}
v["values"]=values;
}
root["entities"]=v;
}
if(getLocale()!="")
{
root["locale"]=getLocale();
}
return w.write(root);
}

Context& addState(std::string state)
{
states.push_back(state);
return *this;
}

std::vector<std::string>& getStates()
{
return states;
}

Context& setReferenceTime(std::string ref)
{
referenceTime=ref;
return *this;
}

std::string getReferenceTime()
{
return referenceTime;
}

Context& setTimezone(std::string tz)
{
timezone=tz;
return *this;
}

std::string getTimezone()
{
return this->timezone;
}

Context& addEntity(ContextEntity& e)
{
entities.push_back(e);
return *this;
}

std::vector<ContextEntity>& getEntities()
{
return entities;
}

Context& setLocale(std::string l)
{
locale=l;
return *this;
}

std::string getLocale()
{
return locale;
}

};
> although MessageRequest has the function SetMessage()
¿who's talking about `MessageRequest'?
The error said «'setMessage': is not a member of 'witpp::Request'»
you do m.setParameter(p).setMessage(/**/), .setParameter() returns a `Request', not a MessageRequest. And a `Request' does not have a .setMessage() member function

no need to do everything in one line.

also, ¿ever heard about indentation?
oops, this is sight problem (when it makes you not to be able to debug properly)
i know about indentation, but it makes the code inaccessible for me at least to read (as i'm using a screen reader called nvda to read)
finally, with your help i've fixed it.
thanks
Topic archived. No new replies allowed.