xxxxxxxxxx
struct TestStruct {
int id;
TestStruct() : id(42)
{
}
};
xxxxxxxxxx
//function having struct as a parameter
#include <iostream>
#include <string>
using namespace std;
struct car{
string name;
string color;
int maxSpeed;
int model;
};
void fun (car x){
cout << "Name: " << x.name << endl;
cout << "Model: " << x.model << endl;
cout << "Color: " << x.color << endl;
cout << "Maximum speed: " << x.maxSpeed << endl;
}
int main(){
car c1 = {"BMW", "Red", 250, 2022};
car c2 = {"Mercedes", "Black", 220, 2019};
fun (c1);
fun (c2);
}
xxxxxxxxxx
# Definition of a singly linked list
struct ListNode {
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
xxxxxxxxxx
struct Block {
vk::DeviceMemory memory;
vk::DeviceSize offset;
vk::DeviceSize size;
bool free;
void *ptr = nullptr; // Useless if it is a GPU allocation
bool operator==(Block const &block);
};
bool Block::operator==(Block const &block) {
if(memory == block.memory &&
offset == block.offset &&
size == block.size &&
free == block.free &&
ptr == block.ptr)
return true;
return false;
}