问题列表 - 第41988页

C/C++有没有使用相对路径的交叉平台方式?

我正在用SDL编写一个小游戏,文件的结构如下:

"src/game /"同时包含.h和.cpp源文件.

"data /"有游戏文件,如地图,tilesets,sprite等......

例如,我将使用以下代码加载精灵.

spriteLib.loadSprite("data/sprites/sprite-ghost.bmp");
Run Code Online (Sandbox Code Playgroud)

要将此字符串转换为绝对路径,我在函数的前4行中包含这些行:

SSprite CSpriteLib::loadSprite(std::string file)
{
    //Converting the file path
    char converted[128];
    realpath(file.c_str(),converted);
    file = converted;
Run Code Online (Sandbox Code Playgroud)

但是这样程序只能在liux下编译...所以如果有人知道另一种方法,我会很感激.

c++ sdl cross-platform relative-path

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

何时以及如何使用异常处理?

我正在读关于异常处理.我得到了一些关于异常处理的信息,但我有几个问题:

  1. 什么时候抛出异常?
  2. 我们可以使用返回值来表示错误,而不是抛出异常吗?
  3. 如果我通过try-catch块保护我的所有功能,它不会降低性能吗?
  4. 何时使用异常处理?
  5. 我看到一个项目,该项目中的每个函数都包含一个try-catch块(即整个函数内的代码被try-catch块包围).这是一个好习惯吗?
  6. try-catch和__try __except有什么区别?

c++ windows exception-handling exception

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

Python中的"*"是什么意思?

我在python中遇到了一行.

            self.window.resize(*self.winsize)
Run Code Online (Sandbox Code Playgroud)

"*"在这一行中意味着什么?我没有在任何python教程中看到过这个.

python

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

NSScrollView在滚动时跳到底部

我有一个NSScrollView包含一个NSImageView,它根据各种因素调整大小.调整大小时我通常会更改图像,因此我将NSScrollView滚动到顶部.这很好用.但是,当我再次开始滚动NSScrollView时,它会移动几个像素然后(大部分时间)跳转到滚动的底部.跳转一次后,它会正常工作,直到我再次将滚动条移到顶部.这让我疯了.我真正做的就是:

[_imageView setImage: anNSImage];

NSRect frame;

NSSize imageSize = [anNSImage] size];
frame.size = imageSize;
frame.origin = NSZeroPoint;

[_imageView setFrame: frame];
[[_mainScrollview contentView] scrollToPoint: NSMakePoint(0, [_imageView frame].size.height - [_mainScrollview frame].size.height)];
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c nsscrollview

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

"_OBJC_CLASS _ $ _ viewsampleViewController",引自:

我创建了一个视图控制器viewsampleViewController ..它有两个方法setname和getname ..我为该视图控制器创建一个测试用例.我的testcase名称是newTestCase,方法名称是testName.

#import "newTestCase.h"
#import "viewsampleViewController.h"


@implementation newTestCase
Run Code Online (Sandbox Code Playgroud)

在我的testName方法中,

-(void)testName{

 NSString *b=@"hello";
 v =[[viewsampleViewController alloc] init];
 STAssertNotNil(v,@"v doesnt created");
 [v setuname:@"hello"];
 NSString *a=[v getuname];

 STAssertEquals(b,a,@"error:name not equal");
 [v release];

}

-(void)setUp{
 v=[viewsampleViewController alloc];
}

-(void) tearDown{
 [v release];
}
Run Code Online (Sandbox Code Playgroud)

当我建立我有一个错误

 Ld "build/Debug-iphoneos/Unit test.octest/Unit test" normal armv6
cd /Users/anande/Documents/viewsample
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1.3
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -bundle -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -L/Users/anande/Documents/viewsample/build/Debug-iphoneos -F/Users/anande/Documents/viewsample/build/Debug-iphoneos -F/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/Developer/Library/Frameworks -filelist "/Users/anande/Documents/viewsample/build/viewsample.build/Debug-iphoneos/Unit test.build/Objects-normal/armv6/Unit test.LinkFileList" -dead_strip -framework Foundation -framework SenTestingKit -miphoneos-version-min=3.1.3 -o "/Users/anande/Documents/viewsample/build/Debug-iphoneos/Unit test.octest/Unit test"


Undefined symbols: …
Run Code Online (Sandbox Code Playgroud)

iphone unit-testing objective-c

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

Haskell readFile非法Char

我需要读一个包含'ç'ou'á'等字符的文件...问题是当我尝试读取文件时,GHC返回:非法字节序列.有没有解决的办法?

main = do putStr "Insert file path\n"
          a <- getLine
          x <- readFile a
          print x

Main> main
Main> Insert file path
Main> /Users/$HOME/Desktop/File.txt
Main> (illegal byte sequence)
Run Code Online (Sandbox Code Playgroud)

谢谢

io locale haskell file

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

为什么必须在main()之外初始化静态成员?

为什么这在C++中无效?

class CLS
{
public:
    static int X;
};

int _tmain(int argc, _TCHAR* argv[])
{
    CLS::X=100;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ static-members

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

多维数组中的和值

我在PHP中试验数组,我正在设置一个假的环境,其中"团队"记录保存在数组中.

$t1 = array (
        "basicInfo" => array (
            "The Sineps",
            "December 25, 2010",
            "lemonpole"
        ),
        "overallRecord" => array (
            0,
            0,
            0,
            0
        ),
        "overallSeasons" => array (
            "season1.cs" => array (0, 0, 0),
            "season2.cs" => array (0, 0, 0)
        ),
        "matches" => array (
            "season1.cs" => array (
                "week1" => array ("12", "3", "1"),
                "week2" => array ("8", "8" ,"0"),
                "week3" => array ("8", "8" ,"0")
            ),
            "season2.cs" => array (
                "week1" => array ("9", "2", "5"),
                "week2" …
Run Code Online (Sandbox Code Playgroud)

php arrays foreach for-loop multidimensional-array

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

Android AnimationDrawable,为什么总是拍两次?

我的代码:


package net.tq5.bubbleexplosion;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class BubbleExplosionActivity extends Activity {
 public static final String TAG = "BubbleExplosionActivity";
 /** Called when the activity is first created. */
 private FrameLayout parent;
 private ExplosionView customView;
 private AnimationDrawable exal;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // set no title;
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
  // Create a FrameLayout and set the background; …
Run Code Online (Sandbox Code Playgroud)

animation android drawable

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

如何在 macOS 上的 Xcode 动态库中解开从 C++ 导出的符号

我一直在尝试用 C++ 开发一个可以在应用程序中运行时加载的动态库。我终于成功了,但它有点难看。我有一个函数,它将指向 C++ 类的指针作为参数,如下所示:

bool registerGrindPlugin( Grind::PluginManager* mgr );
Run Code Online (Sandbox Code Playgroud)

但当然它被导出为:

_Z19registerGrindPluginPN5Grind13PluginManagerE
Run Code Online (Sandbox Code Playgroud)

我尝试了一个带有简单函数的 .c 文件,它可以很好地导出为“registerGrindPlugin”,但当然我不能以这种方式传递 C++ 类作为参数。

所以...我的问题是,有没有办法对导出的符号进行解开或别名,这样我就不必在 dlsym 调用中使用像 Z19registerGrindPluginPN5Grind13PluginManagerE 这样的怪物?

我确实看到了一些关于 -alias_list 作为链接器选项的内容,但我还没有完全弄清楚如何在 Xcode 中使用它。如果这是解决方案,有人可以提供有关如何使用它的更多详细信息吗?

macos xcode symbols dylib

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