2017-02-08 2 views
0

このエラーは混乱していますが、実際に間違っているものとしてVisual Studioが最も説明的ではありません。誰も助けることができますか?オーバーロードされた関数は戻り値の型によってのみ異なります

オーバーロード関数は、あなたがちょうどその戻り値の型を変更することで、メソッドをオーバーロードすることはできません「& vec3をフロート::演算子[](unsigned int型)」

/* 
* vec3.cpp 
*/ 
#include <iostream> 
#include "vec3.h" 

vec3::vec3() { 
    data[0] = 0; 
    data[1] = 0; 
    data[2] = 0; 
} 
vec3::vec3(float x, float y, float z) { 
    data[0] = x; 
    data[1] = y; 
    data[2] = z; 
} 
float vec3::operator[](unsigned int index) {    ///Thrown on these 2 functions 
    return data[index]; 
} 
const float& vec3::operator[](unsigned int index) const { 
    return data[index]; 
} 


/* 
* vec3.h 
*/ 

#ifndef VEC3_H 
#define VEC3_H 

class vec3{ 
private: 
    float data[3]; 
public: 
    ///---------------------------------------------------------------------- 
    /// Constructors 
    ///---------------------------------------------------------------------- 
    vec3(); 
    vec3(float x, float y, float z); 

    ///---------------------------------------------------------------------- 
    /// Getters/Setters 
    ///----------------------------------------------------------------------  
    /// Returns the value at index 
    float operator[](unsigned int index) const; 

    /// Returns a reference to the value at index 
    float& operator[](unsigned int index); 
+1

関数の宣言と定義が一致しません。戻り値の型: 'float'と' const float& '、' float& 'vs' float'です。 – songyuanyao

答えて

0

からのみ戻り値の型によって異なります。違いは、メソッド記述の引数の型にある必要があります。

関連する問題