我有window_types.cpp
#include <string>
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "SDL/SDL_ttf.h"
#include "../../utils/SDL_functions.h"
#include "../../utils/utilsf.h"
#include "../../extra_data/extra_data.h"
#include "window.h"
#include "window_types.h"
using namespace std;
using namespace windows;
message_window::message_window(string title,string con,int a[],int b[]) : bwindow(title, 300, 200, 300, 200,a,b){
vector <string> content_ordered;
string new_lines = "";
for (int x = 0;x < con.size();x++){
if (utilsf::cts(con[x]) == "/" and utilsf::cts(con[x]) == "r"){
content_ordered.push_back(new_lines);
new_lines = "";
x+=2;
}
new_lines = new_lines + utilsf::cts(con[x]);
}
SDL_Color textColor = {0, 0, 0};
TTF_Font *font = fonts::load_john_han(15);
int h = 0;
for (int x = 0;x < content_ordered.size();x++){
SDL_Surface* text_surface = TTF_RenderText_Solid(font,content_ordered[x].c_str(),textColor);
apply_surface(5,h,text_surface,content);
h += text_surface->h + 3;
}
}
/*void windows::message_window::start(string title,vector <string> content,int s){
int yp = 200;
int xp = 300;
int w = 100;
int h = 50;
int a[4];
int b[4];
a[0] = utilsf::randrange(0,256,s);
a[1] = utilsf::randrange(0,256,s);
a[2] = 200;
a[3] = 255;
b[0] = 200;
b[1] = utilsf::randrange(0,256,s);
b[2] = utilsf::randrange(0,256,s);
b[3] = 255;
bwindow(title,xp,yp,w,h,a,b);
}*/
void windows::message_window::test(){
}
message_window* get_message_window(string title,string msj,int s){
int a[4];
int b[4];
a[0] = utilsf::randrange(0,256,s);
a[1] = utilsf::randrange(0,256,s);
a[2] = 200;
a[3] = 255;
b[0] = 200;
b[1] = utilsf::randrange(0,256,s);
b[2] = utilsf::randrange(0,256,s);
b[3] = 255;
message_window *w = new message_window(title,msj,a,b);
return w;
}
这里window_types.h
/*
* window_types.h
*
* Created on: Aug 10, 2013
* Author: newtonis
*/
#ifndef WINDOW_TYPES_H_
#define WINDOW_TYPES_H_
#include <string>
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_gfxPrimitives.h"
#include "SDL/SDL_ttf.h"
#include "../../utils/SDL_functions.h"
#include "window.h"
#include "../../extra_data/extra_data.h"
using namespace std;
namespace windows{
class message_window : public bwindow{
private:
vector <string> message;
string title;
public:
message_window(string,string,int a[],int b[]);
void start(string,vector<string>,int);
void test();
};
message_window* get_message_window(string,string,int);
}
#endif /* WINDOW_TYPES_H_ */
在这里我调用函数get_message_window,我得到错误“未定义引用`windows :: get_message_window(std :: string,std :: string,int)”
#include <vector>
#include <string>
#include "SDL/SDL.h"
#include "../utils/event.h"
#include "window/window.h"
#include "window/window_types.h"
#include "stage.h"
#include <iostream>
using namespace std;
using namespace windows;
stage::stage(){
int a[4];
a[0] = 100;
a[1] = 150;
a[2] = 200;
a[3] = 255;
int b[4];
b[0] = 245;
b[1] = 218;
b[2] = 129;
b[3] = 255;
add_window( new bwindow("Test window",20,20,200,200,a,b) );
//ERROR HERE!
message_window *w = windows::get_message_window("hello","hello",5);
add_window(w);
}
void stage::graphic_update(SDL_Surface* screen){
for (int x = 0;x < windws.size();x++){
windws[x]->graphic_update(screen);
}
}
void stage::logic_update(events *evs){
for (int x = 0;x < windws.size();x++){
windws[x]->logic_update(evs);
}
}
void stage::add_window(bwindow *win){
cout<<" Window titled "<<win->get_name()<<" added"<<endl;
windws.push_back(win);
}
答案 0 :(得分:3)
显然,标题中的函数声明(您尚未显示)将函数置于名称空间windows
中。但是函数定义在全局命名空间中。换句话说,您已经实现了一个名为::get_message_window
的函数,但是您正在调用另一个名为windows::get_message_window
的函数。
将声明从命名空间中取出,或将定义放入命名空间。
答案 1 :(得分:2)
根据错误消息:
message_window* get_message_window(string title,string msj,int s){
应该是:
message_window* windows::get_message_window(string title,string msj,int s){