2016-04-19 66 views
0

コンパイラ(Mingw32)は "util.h"の21行目にコンパイルエラーがあると主張しています。C4716関数は値を返しても値を返さなければなりません

#ifndef UTIL_H 
#define UTIL_H 
#include <string> 
#include <list> 
#include "treeitem.h" 
using namespace std; 

#include <algorithm> 
#include <functional> 
#include <cctype> 
#include <locale> 
#include <QList> 


static inline string &ltrim(string &s){} 
static inline string &rtrim(string &s){} 
static inline string &trim(string &s){} 
static inline string func_1(string txt,size_t start, size_t end){} 
static inline size_t func_2(string txt, size_t index){} 
static inline string replace(string& str, const string& from, const string& to){} 
vector<TreeItem *> parse(string dat){} 

#endif // UTIL_H 

ライン21は、「util.cpp」内の関数のプレースホルダです。 (util.cppをの抜粋)

vector<TreeItem *> parse(string dat) 
{ 
    vector<TreeItem *> final {}; 
    while (dat.find("{") <= dat.length()){ 
     TreeItem * temp = new TreeItem; 
     temp->setText(QString::fromStdString(replace(replace(replace(replace(trim(func_1(dat,0,dat.find('{'))),"\n","")," ",""),"}",""),"=",""))); 
     QList<TreeItem *> ref = parse(func_1(dat, dat.find("{")+1,func_2(dat,dat.find('{')))); 

     for(int j = 0; j < ref.size(); j++) 
     { 
      temp->setParent(ref.at(j)); 
      final.push_back(temp); 
      dat = func_1(dat,func_2(dat,dat.find('{')),dat.length()); 
     } 
    } 
    return final; 
} 

明らかにそれはそう、コンパイラはエラーを与えるべきではない何かを返します。ループが常にtrueに評価されることは問題ではありません。なぜなら、私が "return final"を移動しても、ループの前ではまだエラーがスローされます。

+2

ヘッダファイル内で '{} 'とは何ですか? – AnT

+0

**コンパイラエラーとは何ですか?**これがなければ、本当にあなたを助けることができません。 –

+1

@MaxLybbert:タイトルにあります。 –

答えて

2

問題は行にあります。

static inline string &ltrim(string &s){} 
static inline string &rtrim(string &s){} 
static inline string &trim(string &s){} 
static inline string func_1(string txt,size_t start, size_t end){} 
static inline size_t func_2(string txt, size_t index){} 
static inline string replace(string& str, const string& from, const string& to){} 
vector<TreeItem *> parse(string dat){} 

それらのすべてが空の実装を提供し、彼らは単なる宣言ではありません。それらを宣言だけにしたい場合は{};に置き換える必要があります。

static inline string &ltrim(string &s); 
static inline string &rtrim(string &s); 
static inline string &trim(string &s); 
static inline string func_1(string txt,size_t start, size_t end); 
static inline size_t func_2(string txt, size_t index); 
static inline string replace(string& str, const string& from, const string& to); 
vector<TreeItem *> parse(string dat); 
+0

'inline'関数が本体を持つべきではないので、コンパイラは使用を見てそれを拡張できますか? – Barmar

+0

@Barmarでは、関数をインラインで宣言し、後で定義することができます。 –

2

ヘッダーの中カッコを削除します。ヘッダーにプロトタイプ、ソースファイルに実装を定義します。

関連する問題