小编Mah*_*esh的帖子

前瞻性类别,功能

当函数的前向声明在源文件(.cpp)中工作时,为什么同样的不适用于类?

谢谢.

// main.cpp

void forwardDeclaredFunction() ; // This is correct 

class One ; // Why this would be wrong 

int One:: statVar = 10 ;

void
One :: anyAccess() {

 std::cout << "\n statVar:\t " << statVar ;
 std::cout << "\n classVar:\t" << classVar ;
}

class One {

 public:
  void anyAccess() ;
  static int statVar ;

 private:
  int  classVar ;

} ;


int main (int argc, char * const argv[]) {

 One *obj = new One ;

        return …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

10
推荐指数
2
解决办法
3万
查看次数

当我从公共成员函数返回引用时,为什么我可以公开私有成员?

在代码片段中,我能够访问类范围之外的私有成员变量.虽然不应该这样做,为什么在这种情况下允许?通过引用接收返回的私有变量是不好的做法?

#include <iostream>
#include <cstdlib>

class foo
{
    int x;
    public:
        foo(int a):x(a){}
        int methodOne() { return x; }
        int& methodTwo() { return x; }
};

int main()
{
    foo obj(10);
    int& x = obj.methodTwo();
    x = 20;              // With this statement, modifying the state of obj::x

    std::cout << obj.methodOne();
    getchar();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

关于这种方法,返回类型传达了什么?而且我什么时候应该有这种类型的返回类型?

int& methodTwo() { return x; }
Run Code Online (Sandbox Code Playgroud)

PS:如果主题行含糊不清,我很抱歉.有人可以将其更改为与此处相关的内容.谢谢.

c++ function return-type

10
推荐指数
2
解决办法
1万
查看次数

AVAudioRecorder averagePowerForChannel始终返回-120.0

我正在尝试使用AVAudioRecorder的averagePowerForChannel方法来监控iPad/iPhone应用程序的麦克风输入电平.我有一个回调轮询循环中的平均水平 - 在iPhone上它工作正常并返回合理的水平,但由于某种原因在iPad上它总是返回-120.0.

这是我的一些设置代码:

- (void) setupMic {
if (micInput) {
    [micInput release];
    micInput = nil;
}
NSURL *newURL = [[NSURL alloc] initFileURLWithPath:@"/dev/null"];

NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] init];

[recordSettings setObject:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey: AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:22050.0] forKey: AVSampleRateKey];
//  [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityLow] forKey: AVEncoderAudioQualityKey];

micInput = [[AVAudioRecorder alloc] initWithURL:newURL settings:recordSettings error:nil];
//  [micInput setMeteringEnabled:YES];

[newURL release];
[recordSettings removeAllObjects];
[recordSettings release];
}
Run Code Online (Sandbox Code Playgroud)

以及我的开始录制方法:

- (void) startRecording { …
Run Code Online (Sandbox Code Playgroud)

avfoundation avaudiorecorder ios avaudiosession

10
推荐指数
1
解决办法
5758
查看次数

重新定义; 不同的基本类型(typedef struct)

当在不同的文件中定义结构时,我在尝试使结构正常工作时遇到了一些麻烦.据我所知,错误告诉我结构被定义了两个不同的时间.我相信也许我可能需要在某处使用extern?我尝试过试验并在Google上寻求帮助,但无济于事.

任何帮助都将非常感谢,谢谢.我的所有四个文件都在下面.

文件:Foo.h

typedef struct
{
    int number;
} my_struct;    // Redefinition; different basic types
Run Code Online (Sandbox Code Playgroud)

文件:Foo.c

#include "Foo.h"
#include "Bar.h"
#include <stdio.h>

my_struct test;

int main(void)
{
    test.number = 0;
    DoSomething(&test);
    printf("Number is: ", &test.number);
}
Run Code Online (Sandbox Code Playgroud)

文件:Bar.h

#include "Foo.h"

void DoSomething(my_struct *number);
Run Code Online (Sandbox Code Playgroud)

文件:Bar.c

#include "Bar.h"

void DoSomething(my_struct *number)
{
    number->number = 10;
}
Run Code Online (Sandbox Code Playgroud)

c struct typedef extern

10
推荐指数
1
解决办法
2万
查看次数

cin.eof()功能

我理解cin.eof()测试流格式.在输入时,输入错误时不会到达字符结尾.我在MSV C++ 2010上对此进行了测试,并没有理解奇怪的结果.无论我给出什么输入,我都会收到程序中存在的格式错误消息.

#include <iostream>
using namespace std;

int main()
{
    int i;
    cin>> i;

    if(!cin.eof())
    {
        cout<< "\n Format Error \n";
    }
    else
    {
        cout<< "\n Correct Input \n";
    }

    getchar();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

结果我预计:

i =的值

  1. 10 => 正确输入但输出为格式错误
  2. 12a => 格式错误

有人可以解释我哪里错了.谢谢.

c++ iostream visual-c++

8
推荐指数
3
解决办法
8万
查看次数

使用CryptUnprotectData解密WEP wlan配置文件密钥

我正在尝试使用CryptUnprotectData解密WEP配置文件的密钥.我获取配置文件密钥的方法是使用netsh导出配置文件.

netsh wlan export profile name="MyWEP" folder="./"
Run Code Online (Sandbox Code Playgroud)

现在,我手动将密钥材料从netsh命令生成的.xml文件复制到我的程序.顺便说一下,我正在解密的是 -

DATA_BLOB DataOut, DataVerify;
DataOut.cbData = encryptData.length();
DataOut.pbData = (BYTE*)("I_Manually_Copy_The_WEP_Key_Here");

if (CryptUnprotectData( &DataOut,
                        NULL,
                        NULL,
                        NULL,
                        NULL,
                        0,
                        &DataVerify))
{
    printf("The decrypted data is: %s\n", DataVerify.pbData);
}
else
{
    printf("Failed. Error Code: %d", GetLastError());
}
Run Code Online (Sandbox Code Playgroud)

但我收到错误代码13引用无效数据.我究竟做错了什么 ?在Win 7及更高版本中,我可以直接使用WlanGetProfile和参数WLAN_PROFILE_GET_PLAINTEXT_KEY.但我在Vista没有选择使用CryptUnprotectData函数.我这里看过类似的帖子,但是没有得到太多有用的信息.此外,我使用相同的系统具有相同的用户登录凭据.有人可以建议我怎么办?

PS:我在Windows桌面SDK论坛上发布了相同的问题,但还没有得到回复.试试我的运气吧.

c encryption wlanapi wep windows-vista

7
推荐指数
1
解决办法
7842
查看次数

卸载软件

我的产品有一个帮助程序可执行文件来卸载所有相关的子产品.我根据所有子产品的升级代码卸载.

首先,我使用MsiEnumRelatedProducts函数从升级代码中获取产品代码.然后我尝试使用MsiConfigureProductEx函数卸载产品.

问题MsiConfigureProductEx是返回错误.

调用函数:MsiConfigureProductsEx
返回代码:1605(0x00000645)
描述:此操作仅对当前安装的产品有效.

为什么MsiEnumRelatedProducts返回无效的产品代码?我搜索了Windows注册表,看看是否存在这样的产品代码.没有.如何调试问题?

编辑:添加了重现问题的最小代码.

// UpgradeCodes is an array having upgrade codes of all modules.

TCHAR lpProductCode[GUID_STR_LENGTH];
const TCHAR tszNoReboot[] = _T("REMOVE=ALL REBOOT=ReallySuppress DISABLE_REBOOT_PROMPT=1");

for (size_t i = 0; i < sizeof(UpgradeCodes) / sizeof(UpgradeCodes[0]); i++)
{
   tstring tstrUpgradeCode = UpgradeCodes[i];

   DWORD dwIndex = 0;
   size_t status;

   // for each of the upgrade code, get all the products
   do
   {
       status = MsiEnumRelatedProducts(UpgradeCodes[i], 
                                       0, 
                                       dwIndex, 
                                       lpProductCode);
       if (ERROR_SUCCESS == …
Run Code Online (Sandbox Code Playgroud)

windows installer winapi windows-installer

7
推荐指数
2
解决办法
1736
查看次数

与科学计算器相比,Math.cos显示不同的答案

我用javascript创建了一个计算矢量坐标的程序,一切都很顺利,因为我有正确的公式,但是当我尝试在javascript中使用Math.cos来计算143.1301的余弦时,它从科学计算器返回0.1864而不是0.7999为什么是那?任何人都可以向我解释原因吗?还请给我这个问题的解决方案...在此先感谢... :)这里;我的代码示例

function cyltoxec(a)  
{
    ans = Math.cos(a);  
    return ans.toFixed(4);
}
var = x;
return cyltoxec(x);
Run Code Online (Sandbox Code Playgroud)

javascript

6
推荐指数
2
解决办法
2274
查看次数

std :: string的每个字符的地址

我试图打印每个角色的地址std::string.但是我不知道内部发生了什么,std::string这导致了这个输出,而对于数组,它给出了我预期的地址.有人可以解释一下发生了什么吗?

#include <iostream>
#include <string>

using namespace std;

int main(){

   string str = "Hello";
   int a[] = {1,2,3,4,5};

   for( int i=0; i<str.length(); ++i )
      cout << &str[i] << endl;

   cout << "**************" << endl;

   for( int i=0; i<5; ++i )
      cout << &a[i] << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

Hello
ello
llo
lo
o
**************
0x7fff5fbff950
0x7fff5fbff954
0x7fff5fbff958
0x7fff5fbff95c
0x7fff5fbff960
Run Code Online (Sandbox Code Playgroud)

c++ arrays string memory-address

6
推荐指数
1
解决办法
5977
查看次数

Java:了解String replaceAll()方法

我想在这里找出这个问题的答案.

首先,

blah[abc] = blah[abc].replaceAll("(.*) (.*)", "$2, $1");
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释一下(.*),$ 2和$ 1是什么?

其次,当我在for语句中嵌套以便反转字符串的两个部分时,我遇到异常错误.我想知道是否有人知道为什么会这样.

谢谢

编辑:这是我收到的错误

线程"main"中的异常java.lang.ArrayIndexOutOfBoundsException:1在ChangeNames.main(ChangeNames.java:21)

java regex replaceall

5
推荐指数
1
解决办法
7443
查看次数