我一直在學習 c 并嘗試實作我在頭檔案和源檔案的解決方案中創建的類以供將來使用。在頭檔案中我實作了以下定義和方法
#ifndef CVECTOR_H
#define CVECTOR_H
class cVector {
public:
float Xpos;
float Ypos;
float Zpos;
cVector(float x, float y, float z);
void Print();
float Length();
cVector Negation();
cVector Normalisation();
};
#endif
在源檔案(.cpp)中我試圖定義
#include<iostream>
#include<math.h>
#include "cVector.h"
#include <float.h>
int main()
{
cVector(float x, float y, float z) { // Constructor with parameters
Xpos = x;
Ypos = y;
Zpos = z;
};
}
但是我得到了 float x 不是有效型別名稱的錯誤,錯誤是什么?
我希望實作定義變數 Xpos、Ypos、Zpos 的 cVector 輸入
uj5u.com熱心網友回復:
這將是正確的語法。這需要放在外面main():
cVector::cVector(float x, float y, float z) { // Constructor with parameters
Xpos = x;
Ypos = y;
Zpos = z;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/450460.html
上一篇:python中的類屬性和函式遞回
