小编us2*_*012的帖子

何时从列表中弹出对象?

这可能是一个非常愚蠢/基本的问题,但我无法弄明白.我会告诉你我的想法 - 如果我错了,请纠正我.

当我们使用STL容器存储原始指针时,我们必须在它们之后进行清理:

std::list<animal*> alist;
animal *a = new animal();
alist.push_back(a);
...
animal *b = alist.front();
alist.pop_front();
//do stuff with b
delete b;
Run Code Online (Sandbox Code Playgroud)

如果我们存储对象会发生什么?我的理解是,如果一个装满了对象的容器超出范围,它内部的所有对象都将被销毁.正确?

但是,如果我们使用std::list<T>.pop_front()例如从容器中删除对象怎么办?

std::list<animal> alist;
{
  animal ani();
  //ani is inserted at the end of the list (it IS ani rather than a copy 
  //since push_back accepts const T&)
  alist.push_back(ani);
} //nothing is deallocated/destroyed here
...
{
  animal b = alist.front(); //b is now a copy(?!) of the front element
                            //created via copy …
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

将CString与sprintf一起使用

我有一些C++代码,我需要在sprintf中使用CString.在这段代码中,我创建的文件名是由sprintf定义的CStrings.代码如下.

double Number;     
Number = 0.25; 

char buffer [50];

CString sFile;
sFile = sprintf(buffer,"TRJFPICD(%3.3f).txt",Number);

CString SFFile;
SFFile = sprintf(buffer,"TRJFPICV(%3.3f).txt",Number);

CString SFFFile;
SFFFile = sprintf(buffer,"TRJFPICA(%3.3f).txt",Number);
Run Code Online (Sandbox Code Playgroud)

所需的文件名是TRJFPICD(0.25).txt, TRJFPICV(0.25).txt,和TRJFPICA(0.25).txt.我必须使用CStrings代码.

我得到的错误是' operator ='含糊不清.

c++ printf cstring

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

xamarin组件无法解析组装

我正在尝试构建一个xamarin组件.我从Binding项目创建了一个SomeLibrary.dll.使用这个SomeLibrary.dll和组件模板(https://components.xamarin.com/guidelines ),我生成了一个SomeLibrary-1.0.xam组件.

我执行此命令将SomeLibrary组件安装到Xamarin Studio上(因此我可以在将组件提交到商店之前对其进行测试):

mono xamarin-component.exe install /Users/somedeveloper/Desktop/XamarinComponent/component-template-master/SomeLibrary-1.0.xam

(http://forums.xamarin.com/discussion/5640/test-component-packaging推荐)

现在,我正在尝试测试我的SomeLibrary组件.我创建了一个全新的项目,将组件添加到我的项目中,写了几行使用SomeLibrary api,并在构建和运行时遇到以下错误.我在这里迷茫和困惑,任何想法,建议都会很棒.^^.

我从错误中看到的主要是:

error MT2002: Failed to resolve assembly: 'SomeLibrary, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

它似乎在抱怨某种PublicKeyToken.这是什么?我是否必须为SomeLibrary组件生成PublicKeyToken?如果是这样,我如何生成PublicKeyToken.

感谢并感谢任何帮助,建议或评论!^ _ ^!,

完整错误日志

Building: SomeLibraryComponent (Debug|iPhone)

Detecting signing identity...
Provisioning Profile: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Signing Identity: "iPhone Developer: XXXXXXXXXX (ALKJLKJSLDKJFLJ)"
App ID: "SDLFJLKSDJF.SomeLibrarycomponent"
Performing main compilation...
/Library/Frameworks/Mono.framework/Versions/3.2.3/bin/mcs /noconfig "/r:/Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll" -nostdlib     "/out:/Users/somedeveloper/projects/SomeLibraryComponent/SomeLibraryComponent/bin/iPhone/Debug/SomeLibraryComponent.exe" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" "/r:/Users/somedeveloper/projects/SomeLibraryComponent/Components/SomeLibrary-1.0/lib/ios/SomeLibrary.iOS.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" /nologo /warn:4 /debug:full /optimize- /codepage:utf8 "/define:DEBUG;__MOBILE__;__IOS__"  /t:exe "/Users/somedeveloper/projects/SomeLibraryComponent/SomeLibraryComponent/Main.cs" "/Users/somedeveloper/projects/SomeLibraryComponent/SomeLibraryComponent/AppDelegate.cs" "/Users/somedeveloper/projects/SomeLibraryComponent/SomeLibraryComponent/SomeLibraryComponentViewController.cs" "/Users/somedeveloper/projects/SomeLibraryComponent/SomeLibraryComponent/SomeLibraryComponentViewController.designer.cs"
Compilation succeeded - 1 warning(s)

/Users/somedeveloper/projects/SomeLibraryComponent/SomeLibraryComponent/SomeLibraryComponentViewController.cs(48,24): warning …
Run Code Online (Sandbox Code Playgroud)

mono components .net-assembly xamarin.ios xamarin

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

无法使用C ++ 11实例化抽象类

为什么在运行时不能使用接口之类的抽象类。

我得到的输出:

1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(615): error C2259: 'Creature' : cannot instantiate abstract class
1>          due to following members:
1>          'std::string Creature::Move(std::vector<std::string,std::allocator<_Ty>> &)' : is abstract
1>          with
1>          [
1>              _Ty=std::string
1>          ]

1>          visual studio 2013\projects\cpp_demo\cpp_demo\creature.h(9) : see declaration of 'Creature::Move'
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(614) : while compiling class template member function 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)'
1>          with
1>          [
1>              _Ty=Creature
1>          ]

1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(752) : …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

ubuntu 中有库的默认路径吗?

伙计们!

我正在使用ubuntu 12.04并尝试编译一个boost测试程序。我安装了boost

sudo apt-get install libboost-all-dev
Run Code Online (Sandbox Code Playgroud)

所以,我不知道在哪里可以找到我的图书馆。我尝试使用以下命令进行编译

g++ -lboost_system -lboost_thread boost_test.cpp
Run Code Online (Sandbox Code Playgroud)

认为也许有一些默认路径,ubuntu 自动安装 boost,但这是错误的,我有以下内容:

/tmp/ccTKXzTR.o: 在函数 __static_initialization_and_destruction_0(int, int)': boost_test.cpp:(.text+0xcc): undefined reference to boost::system::generic_category()' boost_test.cpp:(.text+0xd8): 未定义引用boost::system::generic_category()' boost_test.cpp:(.text+0xe4): undefined reference to boost::system::system_category()' /tmp/ccTKXzTR.o:在函数 boost::system::error_code::error_code()': boost_test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference toboost::system::system_category()' /tmp/ccTKXzTR.o: 在函数 boost::asio::error::get_system_category()': boost_test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference toboost::system::system_category()' /tmp/ccTKXzTR.o: 在函数 boost::asio::detail::posix_tss_ptr_create(unsigned int&)': boost_test.cpp:(.text._ZN5boost4asio6detail20posix_tss_ptr_createERj[_ZN5boost4asio6detail20posix_tss_ptr_createERj]+0x19): undefined reference topthread_key_create' /tmp/ccTKXzTR.o: 在函数 boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service, boost::asio::detail::task_io_service::thread_info>::context>::~posix_tss_ptr()': boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceENS4_11thread_infoEE7contextEED5Ev]+0x15): undefined reference topthread_key_delete'/tmp/ boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl, unsigned char>::context>::~posix_tss_ptr()': boost_test.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED2Ev[_ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEhE7contextEED5Ev]+0x15): undefined reference toccTKXzTR.o:在函数 pthread_key_delete'collect2 中:错误:ld 返回 …

c++ linux boost compilation

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

String Java查找空格

我在字符串上有一个短语,我想将其拆分为其他5个或更多字符串,不带空格.例如:

String test = "hi/ please hepl meok?";
Run Code Online (Sandbox Code Playgroud)

而且我要 :

String temp1 = "hi/";
String temp2 = "please";
String temp3 = "help";
String temp4 = "meok?";
Run Code Online (Sandbox Code Playgroud)

我不想在数组中添加它,因为我想将temp4拆分为3个以上的字符串.例如

- >>拆分后的>> temp4:

temp4 = "me"
temp5 = "ok"
temp6 = "?"
Run Code Online (Sandbox Code Playgroud)

问这个问题,因为我想编写一个方法来解码来自LinkedHashMap集的字符串短语和一些解码.谢谢.如果我的方式有误,请指导我!:)

java string linkedhashmap

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