我一直在尝试制作一个程序,添加2个不同大小的数组.但我想知道动态增加阵列大小容量?例如:array [4]然后将大小升级为2来制作数组[6] ;? 编辑:没有使用矢量
我尝试创建一个新的ptr但它不起作用.我收到错误:只读变量不可分配.
int *ptr2 = new int[a2.size];
// new ptr2 copies ptr1
for (int i=0; i<(a1.size); i++) {
ptr2[i] = a1.ptr[i];
}
// we want ptr1 to point to ptr2
for (int i=0; i<(a2.size); i++) {
ptr2[i] += a2.ptr[i];
}
delete [] a1.ptr;
a1.ptr=ptr2;
Run Code Online (Sandbox Code Playgroud) 我在这里买了这个humitid /温度传感器:https://www.sparkfun.com/products/10167
我在这里阅读了Datasheed:http: //dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
我尝试从我的c ++类中使用一些基础编程,但我不知道是什么问题?看起来传感器的数据输入没有发送任何东西.在数据表上,我需要发送一个5V的输入信号(20-40ms),然后等待传感器的响应并存储输入的Bits.传感器数据始终为0.我不明白为什么.
/* Code for the RHT03 Sensor 8/5/12 */
int i=0;
int SensorVccPin = 13;
int datapin = 7;
int bitcheck1;
int bitcheck2;
int temp[16];
int humidity[16];
int sensorcheck[8];
void setup()
{
pinMode(SensorVccPin, OUTPUT);
pinMode(datapin, INPUT);
}
void loop()
{
// This is the STEP #1
digitalWrite(SensorVccPin, LOW);
delayMicroseconds(10);
digitalWrite(SensorVccPin, HIGH);
delayMicroseconds(30);
digitalWrite(SensorVccPin, LOW);
/* NEED TO DO BIG NESTED IF STATEMENTS!!!!*/
digitalRead(datapin);
if (digitalRead(datapin) == LOW) // FIRST BIG IF …Run Code Online (Sandbox Code Playgroud) 我正在学习C++而且我遇到过这个,我不明白这个小东西.为什么GetName()函数是字符类型的指针,为什么它是常量?
class Derived: public Base
{
public:
Derived(int nValue)
: Base(nValue)
{
}
const char* GetName() { return "Derived"; }
int GetValueDoubled() { return m_nValue * 2; }
};
Run Code Online (Sandbox Code Playgroud) 这是我的程序,因为这个错误而失败:对'exception'的引用是不明确的.
这是为什么?
是因为我的类名是"异常"而C++已经有了使用名称"exeption"的其他功能吗?例如,在C++中,我们不能使用"int"作为变量.这个逻辑是否也适用于此?谢谢.
#include <iostream>
#include <math.h>
using namespace std;
class exception{
public:
exception(double x,double y ,double z)
{
cout<<"Please input a";
cin>>x;
cout<<"Please input b";
cin>>y;
cout<<"Please input c";
cin>>z;
a=x;
b=y;
c=z;
/*
try{
int sonsAge = 30;
int momsAge = 34;
if ( sonsAge > momsAge){
throw 99;
}
}
catch(int x)
{
cout<<”son cannot be older than mom, Error number :”<<x;
}
*/
try {
if (a==0) {
throw 0;
}
if ((b*b)-(4*a*c)<0) {
throw 1; …Run Code Online (Sandbox Code Playgroud)