我是C ++的新手,并且停留在声明类的语法上。
根据我收集到的信息,您应该将所有声明存储在头文件中,我将其称为clarifications.h;
#pragma once
void incptr(int* value);
void incref(int& value);
class Player
{
public:
int x, y;
int speed;
void Move(int xa, int ya)
{
x += xa * speed;
y += ya * speed;
}
void printinfo()
{
std::cout << x << y << speed << std::endl;
}
};
Run Code Online (Sandbox Code Playgroud)
现在,播放器是一个类,我想将其存储在名为functions.cpp的cpp文件中
我想将上面的Player类移到下面的文件functions.cpp中
#include "common.h"
void incptr(int* value)
{
(*value)++;
}
void incref(int& value)
{
value++;
}
Run Code Online (Sandbox Code Playgroud)
common.h包含;
#pragma once
#include <iostream>
#include <string>
#include "declarations.h"
Run Code Online (Sandbox Code Playgroud)
我认为正在发生的事情是当我在头文件中编写Player类时,它已经在该文件中声明了。如果我将Player类移到functions.cpp中,则需要声明。我不确定编译器在涉及类时期望作为声明。
我试过了;
class Player(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试用Python创建Rubik's Cube,我已经从视觉上表示了这个立方体。如何实施轮换方面有些困难。
我想我正在寻求有关如何执行此操作的反馈。我首先想到的是旋转每个多维数据集的顶点,但是运气不好。
我基本上想从一组多维数据集对象(大小不同)中选择一个切片,对每个对象执行旋转和平移。
import pygame
import random
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1)
)
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7)
)
surfaces = (
(0,1,2,3),
(3,2,7,6),
(6,7,5,4),
(4,5,1,0),
(1,5,7,2),
(4,0,3,6)
)
colors = (
(1,0,0), #Red
(0,1,0), …Run Code Online (Sandbox Code Playgroud)