2016-11-13 2 views
0

**私のメインでは、クラストラボルゴの新しいオブジェクトにノートを追加できませんC++クラステンプレートを使用している場合、非クラス型のリクエストです(メインテンプレートでは定義できません)

ass.add_nota(num); 
** 

私の編集に間違いがあります。

マイ "Trabalho.h" コード:

#include <string> 
 
#include <vector> 
 
#include <iostream> 
 
//#include "Enunciado.h" 
 
//#include "Pessoa.h" 
 

 
using namespace std; 
 

 
class Estudante; 
 
class Enunciado; 
 

 
template <class T> 
 
class Trabalho{ 
 
    static int id_auxiliar; 
 
    string texto; 
 
    int ano; 
 
    int id; 
 
    vector<float> calif; 
 
    T* Enun; 
 
    vector<Estudante*> estudantes; 
 
    vector<Enunciado*> enunciados; 
 

 
public: 
 
    Trabalho(); 
 
    Trabalho(string texto, vector<Estudante*> est, T* en, int ano); 
 
    ~Trabalho(); 
 
    void set_texto(string texto); 
 
    string get_texto(); 
 
    void add_nota(float nota); 
 
    void add_enun(Enunciado* en){Enun = en;}; 
 
    int get_id(){return id;}; 
 
    int get_ano() {return ano;}; 
 
    void reutilizar(int id_enun); 
 
    vector<float> get_calif() {return calif;}; 
 
    vector<Estudante*> get_estudantes() {return estudantes;}; 
 
    Enunciado* get_enunciado() {return Enun;}; 
 

 

 

 
}; 
 

 
#endif

そして、私のメインのコード:

int main(int argc, char const *argv[]) { 
 
\t int n; 
 
\t int m; 
 

 
\t Pesquisa ah(); 
 

 
\t float num = 1.1; 
 

 
\t Trabalho<Pesquisa> ass(); 
 
\t Trabalho<Pesquisa>* tass = new Trabalho<Pesquisa>(); 
 

 
\t ass.add_nota(num); 
 
\t tass->add_nota(num);

#ifndef ENUNCIADO_H_ 
 
#define ENUNCIADO_H_ 
 
#include "trabalho.h" 
 
#include "Pessoa.h" 
 
#include <string> 
 

 
using namespace std; 
 

 
class Enunciado 
 
{ 
 
\t static unsigned int id_auxiliar; 
 
\t const unsigned int id; 
 
\t string titulo; 
 
\t string descricao; 
 
\t vector<int> anos_utilizados; 
 
\t static unsigned int max_util; 
 
public: 
 
\t Enunciado(string titulo, string descricao); 
 
\t virtual ~Enunciado(); 
 
\t int get_id(){return id;}; 
 
\t void set_titulo(string titulo); 
 
\t string get_titulo(); 
 
\t void set_descricao(string descricao); 
 
\t string get_descricao(); 
 
\t vector<int> get_anos_utilizados(); 
 
\t void mod_max_util(int a); 
 
}; 
 

 

 

 
class Pesquisa: public Enunciado{ 
 

 
\t vector<string> ref; 
 
public: 
 
\t Pesquisa(string tit, string des, vector<string> refe); 
 

 
}; 
 

 
class Analise: public Enunciado{ 
 
    vector<string> repositorios; 
 
public: 
 
    Analise(string tit, string des, vector<string> repos); 
 
}; 
 

 
class Desenvolvimento: public Enunciado{ 
 

 
public: 
 
\t Desenvolvimento(string tit, string des); 
 

 
}; 
 

 

 
#endif

どちらの方法私は私のタイプを定義するとき、私は新しいTrabalhoを作成するときに(pesquisaは、#include「Enunciado.h」上のクラス型です。

これが表示されます2 errosです:非クラス型である 『お尻』のメンバー 『add_nota』、 『Trabalho()』テスト用

「説明リソースパスの場所の種類 要求を。 CPP/Trabalho1/srcのライン42のC/C++の問題 「

そして:

説明リソースパスの場所の種類 メソッド 'add_nota'を解決できませんでしたTest.cpp/Trabalho1/src行42意味エラー

誰でも手助けできますか?

ありがとうございました!

+0

ようこそStackoverflow。 MCVEの例(http://stackoverflow.com/help/mcve)を投稿してください。 Trabalho.hは正しくありません(対応する#ifがない#endifがあります)。 – jpo38

+0

実装はどこですか?それをどうやってコンパイルしますか? – jpo38

+0

あまりにも多くの行があるので、私はすべてのコードを投稿しませんでした – Azevinho

答えて

0

あなたのエラーは、残念ながら、C++は、この非常に誤解を招く可能性があり、それはタイプTrabalho<Pesquisa>()のあなたの変数assを宣言し

Pesquisa ah(); 

または

Trabalho<Pesquisa> ass(); 

としてデフォルトコンストラクタを呼び出そうとしています「ゼロ引数の関数がTrabalho<Pesquisa>を返す」という意味であり、コンパイラエラーとはまったく同じです。関数型はクラス型ではないため、メンバーはadd_notaではありません。特にJavaの背景からお越しの方のために、

int main(); 
^ ^^ 
type arguments 
    name 

それは非常によくある間違いだ:あなたはそれをそのように見れば確かに、それは、関数の宣言のように正確を見ません。しかし、それは簡単にC + +プログラマをキャッチすることができますガードもオフにします。詳細情報はhereまたはhereまたはhereであることがわかります。同じエラーメッセージで多くの人が困惑していることがわかります。

あなたがC++ 11言語の改正に準拠したコンパイラを使用している場合は、単にJavaのとは異なり

Trabalho<Pesquisa> ass; 

を残していない場合は、これはありません

Trabalho<Pesquisa> ass{}; 

によって、これらすべての出現箇所を交換してみてください変数が初期化されないままであることを意味するものではありません。これは、デフォルトの(引数のない)コンストラクタを呼び出すC++の方法です。

+0

@Azevinhoようこそ。あなたのコードを見れば、おそらくこの答えの情報の大部分を知っているだろうが、私はそれを書いたサイトの精神の中で、将来ここに来た人たちに役立つように書いている。 –

+0

現時点では、私はfile.cppからfile.hにすべてを移動し、 "()"ブラケットを削除して、スムーズにatmを実行しています。 編集:非常にありがとう! – Azevinho

+0

@Azevinho問題はありません:-)答えが助けてくれましたら、それに目盛りをつけることを検討してください;-) –

関連する問題