小编Car*_*rum的帖子

在c ++类中访问getter setter中的struct变量

好的,我在C++中有这样的东西:

class MyClass{
private:
  int someVariable;
  int someOtherVariable;

  struct structName{
    int someStructVariable;
    int someOtherStructVariable;
  };//end of struct

public:
  //getters & setters for the defined variables.

  int getSomeStructVariable()
  {
    // this does not work I get this error: "error: expected primary-expression
    // before '.' token"
    return structName.someStructVariable;
  } 
};//end of class
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我该如何写我的getter或setter?

c++ getter setter struct

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

指针,NSMutableArray,保留,循环和混乱

可能问题是直截了当但我不理解它.

我有以下iPhone代码

for(int x = 0 ; x < [allFriends count] ; x++)   
{
    Friend *f = [[Friend alloc] init];          
    f = [allFriends objectAtIndex:x];

    if([uid isEqualToString:[f uid]])
    {                                           
        [f AddAlbum:album];
        [allFriends replaceObjectAtIndex:x withObject:f];
     }                              
}
Run Code Online (Sandbox Code Playgroud)

无论我在哪里调用[f release]该应用程序总是崩溃.为什么?(BTW循环运行几千次)

有更有效的方法吗?

我想我提供了足够的代码,如果没有,请告诉我!

谢谢你的帮助!

arrays iphone pointers objective-c

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

有没有办法检查实例是否仍在内存中?

示例:我有一个视图控制器并摆脱它.但是仍然有一个变量保存它的内存地址.访问它会导致EXEC_BAD_ACCESS.当然.但是:有没有办法检查该变量是否仍然有效?即如果它仍然指向内存中存在的东西?

iphone memory-management objective-c objective-c-runtime

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

可可非原子性质

当您查看一些Objective-C代码时,您经常会看到定义为非原子的类属性.为什么?当你不使用线程时,它是否会给你一些性能提升,还是有其他原因?

cocoa properties objective-c atomicity

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

目标c引用和变量

我正在尝试做这样的事情:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"];
[sendCharlieImput executeAndReturnError:nil];
Run Code Online (Sandbox Code Playgroud)

变量charlieImputSelf将作为命令放入终端窗口.但我需要将charlieImputSelf放在2个qoutes之间(如上所述).这显然不是正确的方法.有人可以帮忙吗?

谢谢!以利亚

variables quotes xcode objective-c

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

我可以在iphone目标c的警报中使用NSStrings吗?

我正在尝试创建一个用户单击按钮的应用程序,并弹出一个警告,其中包含文本字段中的文本.但每当我尝试,我只是得到一个空白的警报.这是我的代码:

@synthesize label;

@synthesize textBox1;

@synthesize text;

- (IBAction)buttonClick {
 UIAlertView *someText = [[UIAlertView alloc] initWithTitle: @"Text from textbox1" message: text delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
 [someText show];
 [someText release];
 text = textBox1.text;
 label.text = text;
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么似乎一切都到位应有的样子.我认为答案可能与NSLog()有关.

iphone objective-c alerts nsstring

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

关于在C中等同数组的问题

假设我有两个int数组x和y,它们都有长度3. x = {0,1,2}.

是否有任何一步将x的值分配给y.当我做y = x,并尝试打印y的值,

代码无法编译.

我不想经历编写for循环的痛苦,写y [i] = x [i]

c arrays

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

在另一个文件中引用C++ struct对象?

我正在努力让正在进行的游戏更加模块化.我希望能够在游戏中声明所有room_t对象的单个数组(room_t rooms []),将其存储在world.cpp中并从其他文件中调用它.

下面的截断代码不起作用,但就我所知.我想我需要使用extern但是无法找到一个正常工作的方法.如果我尝试在头文件中声明数组,我会得到一个重复的对象错误(因为每个文件都调用world.h,我假设).

main.cpp中

#include <iostream>
#include "world.h"

int main()
{
    int currentLocation = 0;
    cout << "Room: " << rooms[currentLocation].name << "\n";
    // error: 'rooms' was not declared in this scope
    cout << rooms[currentLocation].desc << "\n";    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

world.h

#ifndef WORLD_H
#define WORLD_H
#include <string>


const int ROOM_EXIT_LIST = 10;
const int ROOM_INVENTORY_SIZE = 10;

struct room_t
{
    std::string name;
    std::string desc;
    int exits[ROOM_EXIT_LIST];
    int inventory[ROOM_INVENTORY_SIZE];
};  

#endif
Run Code Online (Sandbox Code Playgroud)

world.cpp

#include "world.h"

room_t rooms[] = {
  {"Bedroom", "There …
Run Code Online (Sandbox Code Playgroud)

c++ variables struct extern

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

TCL 中带有两个变量的 For 循环

我想将以下c代码转换为TCL。

int a[10],b[10];
int n=20

for (i=1,j=1; i<=n; i+=2,j++)
{
  b[j]=a[i];
}
Run Code Online (Sandbox Code Playgroud)

我需要将这个 for 循环更改为 TCL,我不想使用 TCL 中的 foreach 功能...TCL for 循环结构是否允许两个循环变量???

c tcl

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

LEAL 指令,这是什么意思?

所以首先我通过做分配 edx = y movl 12(%ebp) %edx.

为什么leal (%edx, %edx, 2) , %edx =edx = 3*y

assembly addressing-mode

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