Seeig我是C++的新手我以为我会尝试编写一个非常简单的控制台应用程序来填充2D数组并显示其内容.
但是我写的代码不会编译.
我得到的一些错误是:
错误C2065:'box':未声明的标识符
错误C2228:'.GenerateBox'的左边必须有class/struct/union
这是我的代码:
#include <iostream>
using namespace std;
int main()
{
Box box;
box.GenerateBox();
}
class Box
{
private:
static int const maxWidth = 135;
static int const maxHeight = 60;
char arrTest[maxWidth][maxHeight];
public:
void GenerateBox()
{
for (int i=0; i<maxHeight; i++)
for (int k=0; k<maxWidth; k++)
{
arrTest[i][k] = 'x';
}
for (int i=0; i<maxHeight; i++)
{
for (int k=0; k<maxWidth; k++)
{
cout << arrTest[i][k];
}
cout << "\n";
}
}
};
Run Code Online (Sandbox Code Playgroud)
有什么想法导致这些错误吗?
在命名空间级别直接使用c ++中的枚举是不好的做法?我的意思是没有与任何课程相关联?假设我有一个enum和一个看起来像这样的类,
enum Player { USER, COMPUTER}
class Game {
//Logic of the game.
};
Run Code Online (Sandbox Code Playgroud)
那么我应该宣布玩家枚举为游戏类的成员吗?它应该是私人的吗?
我已经为我的程序添加了一个类并进行了测试.我真的很惊讶有任何真正的错误.这是代码:
#pragma once
#include "Iingredient.h"
#include <string>
#include <vector>
using namespace std;
ref class Recipe{
private:
string partsName;
vector<Iingredient> ing;
public:
Recipe(){}
};
Run Code Online (Sandbox Code Playgroud)
以下是错误:
错误23错误C4368:无法将'partsName'定义为托管'Recipe'的成员:不支持混合类型c:\ users\user\documents\visual studio 2010\projects\smestras2_l1\Recipe.h 10 1 file2_L1
错误24错误C4368:无法将'ing'定义为托管'Recipe'的成员:不支持混合类型c:\ users\user\documents\visual studio 2010\projects\smestras2_l1\Recipe.h 11 1 file2_L1
我google了一下,发现它有关托管和非托管代码.如何解决这个问题?它是否与manged和非托管代码相关?如果是这样的话?
char* stringReturn()
{
char a[] = "Array of characters";
//return a; // I know stack allocation should not be returned
char *b = "Pointer to a string";
return b; // Is it safe ?
}
int main() {
char *str = stringReturn ();
cout<< str;
return 0; }
Run Code Online (Sandbox Code Playgroud)
这是安全的,然后将数据"指向字符串的指针"存储在存储器中.
Compiler: g++ 4.4.3 Boost...: 1.49.0 OS......: Ubuntu
注意:自从我认真使用C++已有15年了,所以我正在重新学习和学习新东西,因为我也尝试学习Boost.
给出以下代码:
1. class Beta {
2. public:
3. std::string name();
4. }
5.
6. class Alpha {
7. public:
8. Beta m_beta;
9. }
10.
11. Alpha one;
Run Code Online (Sandbox Code Playgroud)
由于各种原因,我想使用boost:bind来实现与调用"one.m_beta.name()"相同的结果.我认为以下会这样做:
12. boost::function<std::string(Alpha)>
13. b = boost::bind(
14. &Beta::name,
15. boost::bind(&Alpha::m_beta, _1)
16. );
17. cout << "NAME = " << b(one) << "\n";
Run Code Online (Sandbox Code Playgroud)
但是当我编译(在Ubuntu上的g ++ 4.4.3)时,我收到以下错误:
错误:从'const Beta*'无效转换为'Beta*'
在查看由第13-16行产生的实际类型定义之后,看起来第15行变为'const Beta*',但是包装它的绑定期望'Beta*'.
但是,这个DOES工作:
30. boost::function<std::string(Beta)>
31. p1 = boost::bind(&Beta::name,_1);
32. boost::function<Beta(Alpha)>
33. p2 = boost::bind(&Alpha::m_beta,_1); …Run Code Online (Sandbox Code Playgroud) 问题 - >将固定长度字符串返回到std :: string*.
目标机器 - > Fedora 11.
我必须派生一个函数,它接受整数值并将固定的长度字符串返回给字符串指针 ;
例如 - > int value的范围是0到-127
所以对于int值0 - >它显示000
为值-9 - >它应该返回-009
表示值-50 - >它应该返回-050
表示值为-110 - >它应该返回-110
所以简而言之,在所有情况下,长度应该相同.
我做了什么:我已经根据下面的要求定义了这个功能.
我需要帮助的地方:我已经派生了一个函数,但我不确定这是否是正确的方法.当我在Windows端的独立系统上测试它时,exe有时会停止工作,但是当我在Linux机器上包含这个功能和整个项目时,它可以完美地工作.
/* function(s)to implement fixed Length Rssi */
std::string convertString( const int numberRssi, std::string addedPrecison="" )
{
const std::string delimiter = "-";
stringstream ss;
ss << numberRssi ;
std::string tempString = ss.str();
std::string::size_type found = tempString.find( delimiter );
if( found == std::string::npos )// not found
{ …Run Code Online (Sandbox Code Playgroud) 在GCC 4.6中,即使由于移动构造函数而隐式删除子节点的赋值运算符,也可以继承父节点的赋值运算符.在GCC的后续版本(以及Clang)中,这已不再可能.让子类使用父类赋值运算符的正确方法是什么?
struct A
{
A & operator=(A const & other) = default;
};
struct B : public A
{
B() {}
B(B && other) {}
using A::operator=;
};
int main()
{
B b1, b2;
b1 = b2; // error: use of deleted function because B's operator= is implicitly deleted due to move constructor
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用While循环,它根据用户输入的值循环一定数量的循环(1-576).它由用户单击"开始"按钮激活,但我希望能够使用"Escape"键取消它.
但是,当循环进行时,我无法让程序识别任何按键.
Private Sub OnGlobalKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles kh.KeyDown
lblInput.Text = String.Format("'{0}' Code:{1}", e.KeyCode, CInt(e.KeyCode).ToString())
If e.KeyCode = CType(27, Keys) Then
count = 0
loops = 0
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
我的循环
Private Sub RUNLOOP()
While loops >= 1
' my code that runs in the loop
loop = loop - 1
End While
End Sub
Run Code Online (Sandbox Code Playgroud)
当循环运行时,我的按键不会注册,否则它们会正常注册.
#include<iostream>
#include<memory>
#include<stdio>
using namespace std;
class YourClass
{
int y;
public:
YourClass(int x) {
y= x;
}
};
class MyClass
{
auto_ptr<YourClass> p;
public:
MyClass() //:p(new YourClass(10))
{
p= (auto_ptr<YourClass>)new YourClass(10);
}
MyClass( const MyClass &) : p(new YourClass(10)) {}
void show() {
//cout<<'\n'<<p; //Was not working hence commented
printf("%p\n",p);
}
};
int main() {
MyClass a;
a.show();
MyClass b=a;
cout<<'\n'<<"After copying";
a.show();//If I remove copy constructor from class this becomes NULL(the value of auto_ptr becomes NULL but if …Run Code Online (Sandbox Code Playgroud) 我想检查登录用户是否具有"写入"或"读取和执行"等权限,用于用户用作安装目标的文件夹.
基本上我使用InstallAnyWhere来准备安装程序.我希望安装程序检查给定目标是否具有对登录用户的上述权限,如果用户没有这些权限,安装程序应该抛出警告消息.
我需要使用java完成此操作.有没有办法用java检查这个?
c++ ×7
string ×2
boost-bind ×1
c++-cli ×1
c++11 ×1
coding-style ×1
enums ×1
filesystems ×1
inheritance ×1
java ×1
loops ×1
managed ×1
move ×1
pointers ×1
stringstream ×1
vb.net ×1
visual-c++ ×1
while-loop ×1