我想讓我的網格類建構式接受 drivers_location 引數,但它一直給我這些錯誤。 https://imgur.com/a/y4MZqso
#include <iostream>
#include <string>
using namespace std;
class drivers_location {
public:
drivers_location() = default;
drivers_location(string name, float xx, float yy){
x = xx;
y = yy;
name = driver_name;
}
private:
float x{};
float y{};
string driver_name;
};
class grid {
public:
grid() = default;
grid(drivers_location(string name, float xx, float yy));
private:
};
int main() {
drivers_location p;
float pointx{ 2.0 };
float pointy{ 3.0 };
grid m[5];
m[0] = { {"abdul" , pointx, pointy }};
}
如果可能的話,我希望網格在不使用繼承的情況下接收 drivers_location 的引數
uj5u.com熱心網友回復:
宣告建構式接受引數型別的正確語法driver_location如下所示。driver_location請注意,在定義grid具有 type 引數的建構式時,您不必指定 2 個引數driver_location。
class grid {
public:
grid() = default;
//---vvvvvvvvvvvvvvvv---->this is how we specify that this ctor has a parameter of type drivers_location
grid(drivers_location){
//add your code here
}
private:
};
我還建議使用一本好的 c 書籍。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/512406.html
標籤:C 班级
