我正在努力学习Java.我想在构造函数中有一个枚举作为参数.但是我收到了一个错误.
public class Person {
private int age, weight, height;
private String name;
private enum gender {MALE, FEMALE}
public Person(int age, int weight, int height, String name, enum gender) {
this.age = age;
this.weight = weight;
this.height = height;
this.name = name;
this.gender = gender;
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何处理性别?我尝试过性别,但也没用.
我正在努力用PHP中的GRAPH API提取数据.我不了解Facebook开发者的文档.我也找不到任何帮助的例子.我想让我的API给我以下(在本月的第一天和当月的最后一天之间):
我已经达到了能够提取数据的能力,但是当我测试使用洞察力部分时,它并没有给我数据.例如我有这个:
// Sets the default fallback access token so we don't have to pass it to each request
$fb->setDefaultAccessToken('{access-token}');
try {
$response = $fb->get('/{page-id}/insights/page_impressions?since=1443650400&until=1446246000', $accessToken);
$graphEdge = $response->getGraphEdge();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage(); …Run Code Online (Sandbox Code Playgroud) 所以我想在函数中创建一个数组,其大小由作为参数的数字设置.这是一个例子:
void temp_arr ( const int array_size ) {
int temp_arr[array_size]; //ERROR array_size needs to be a constant value
//Then do something with the temp arr
}
Run Code Online (Sandbox Code Playgroud)
即使参数是const int,它也不起作用.我想不使用全局const而不使用向量.我很好奇,因为我正在学习C++.我希望它能够使每次调用函数时数组大小不同.是否有解决方案或我是否在调用函数之前创建一个const变量和数组?
我有一个表单选择下拉菜单,我想格式化选项的内部文本。每个选项都有月份、年份和标题。我希望每个人都能相互协调。我尝试在选项元素内放置一个表格,看看是否可以强制它,但失败了。我尝试使用不间断空格,但也失败了(我相信是因为字母的字体系列样式)。这是我的代码:
<form>
<label>I would like to style this in a manner in which the months, years, and title are aligned with each other</label>
<select id="news2">
<option selected value="Click Here"></option>
<option value="1"> JAN 2000 - Title 1 </option>
<option value="2"> FEB 1191 - Title 2 </option>
<option value="3"> MAR 2014 - Title 3 </option>
<option value="4"> APR 1995 - Title 4 </option>
<option value="5"> MAY 2034 - Title 5 </option>
<option value="6"> JUNE 2210 - Title 6 </option>
<option value="7"> JULY …Run Code Online (Sandbox Code Playgroud) 好的,我正在学习C++.我想查看一下银行帐户程序有多少文件.我这样做的方法是运行一个循环来运行并尝试打开"0000000001.txt"以查看它是否有效,然后是"0000000002.txt",依此类推.困难的部分是数字有前导零(在.txt之前需要总共10位数).
double num_of_accounts() {
double number_of_accounts = 0;
double count = 0;
double testFor = 0000000000;
ofstream ifile;
string filename = "0000000000";
for (count = 0; 0 < /*MAX_NUMBER_OF_ACCOUNTS*/ 5; count++){
ifile.open(filename + ".txt");
if (ifile) { number_of_accounts++; }
// I would like to increment the number in the filename by 1 here
} // END of for (count = 0; 0 < MAX_NUMBER_OF_ACCOUNTS; count++){
return number_of_accounts;
}
Run Code Online (Sandbox Code Playgroud)
或者可能是一种将double格式化为10位数然后使用to_string()转换为字符串的方法?我试过谷歌搜索它,但我不知道我是否使用了错误的关键字.
如果有帮助,这是在win控制台上.
谢谢
我正在寻找阶乘宏的示例。我没有找到任何有效的东西。有没有一个特定的原因?这是因为 C 的实现吗?
所以,为了让问题更清楚.......我一直无法在 C 的编程语言中找到阶乘宏。我知道你不能在宏中使用递归,但是有一种方法可以有一个迭代阶乘函数。为什么在 C 中不可能有阶乘宏?
作为参考,这里是我发现的阶乘函数迭代实现的示例:
int factorial(int N) {
int product = 1;
for (int j = 1; j <= N; j++)
product *= j;
return product;
}
Run Code Online (Sandbox Code Playgroud)
这是一个进一步了解C语言及其使用宏的问题
请解释为什么这个问题被否决了。这是一个更好地理解C的问题。
因此,经过一些研究,我一直在努力为我的继承类分别设置类头和源代码.以下示例是我的类的缩短版本.我的所有标题都包含警卫,默认构造函数和虚拟析构函数.它们还具有变量所需的getter和setter函数.我将主要只显示变量和包含.
MainProgram.h
#include "FileMgr.h"
#include "InfoMgr.h"
class FileMgr;
class InfoMgr;
class MainProgram
{
private:
FileMgr* fileMgr;
InfoMgr* infoMgr;
public:
.
.
.
}; // !MainProgram
Run Code Online (Sandbox Code Playgroud)
MainProgram.cpp
#include "MainProgram.h"
#include <iostream>
Run Code Online (Sandbox Code Playgroud)
MgrBase.h
#include "MainProgram.h"
#include <string>
class MainProgram;
class MgrBase
{
protected:
MainProgram* mainProgram;
MgrBase() : mainProgram(nullptr) {}
virtual ~MgrBase() {}
public:
virtual bool Init() = 0;
}; // !MgrBase
Run Code Online (Sandbox Code Playgroud)
FileMgr.h
#include "MgrBase.h"
class MainProgram;
class FileMgr : public MgrBase
{
public:
FileMgr(MainProgram* mainProgram);
.
.
. …Run Code Online (Sandbox Code Playgroud)