我一直在使用以下链接中的增强框架来实现我的iPhone Xcode项目:https: //goodliffe.blogspot.com/2010/09/building-boost-framework-for-ios-iphone.html
它工作正常,但我总是得到数百个Apple Mach-O Linker(id)警告:
在__ZN5boost15program_options6detail7cmdline24handle_additional_parserERSt6vectorISsSaISsEE中直接访问全局弱符号__ZTVN5boost17bad_function_callE表示在运行时无法覆盖弱符号.这可能是由使用不同可见性设置编译的不同翻译单元引起的.
如何摆脱代码中的警告?
编辑:通过设置默认隐藏的符号 = YES,我设法摆脱了大多数警告,但还剩下3个不会消失,有人可以告诉我为什么?
再次编辑:重建后剩下的3个警告也消失了!所以我的解决方案确实有效
C++标准规定返回对局部变量(在堆栈上)的引用是未定义的行为,那么为什么许多(如果不是全部)当前编译器只会发出警告呢?
struct A{
};
A& foo()
{
A a;
return a; //gcc and VS2008 both give this a warning, but not a compiler error
}
Run Code Online (Sandbox Code Playgroud)
如果编译器为此代码提供错误而不是警告,那会不会更好?
允许这个代码只用警告编译有什么好处吗?
请注意,这不是一个const可以延长临时使用寿命的参考资料.
为什么C++标准允许对象切片?
请不要向我解释c ++对象切片概念,因为我知道这一点.
我只是想知道这个c ++功能(对象切片)设计背后的意图是什么?
为了获得新手更多的错误?
对于c ++来说,防止对象切片不是更安全吗?
以下是标准和基本切片示例:
class Base{
public:
virtual void message()
{
MSG("Base ");
}
private:
int m_base;
};
class Derived : public Base{
public:
void message()
{
MSG("Derived ");
}
private:
int m_derive;
};
int main (void)
{
Derived dObj;
//dObj get the WELL KNOWN c++ slicing below
//evilDerivedOjb is just a Base object that cannot access m_derive
Base evilDerivedOjb = dObj; //evilDerivedObj is type Base
evilDerivedOjb.message(); //print "Baes" here of course just as c++ …Run Code Online (Sandbox Code Playgroud) 我使用C++作为应用主干和Objective-C用于GUI,这很好.
但是当谈到在Objective-C++(.mm文件)中将这些代码混合在一起时,我有一些问题:
例如,在Objective-C标题中,我可以执行以下操作吗?
#include <vector>
#include <boost\shared_ptr.hpp>
@interface MyClass : NSObject {
std::vector<boost::shared_ptr<CCSprite> > m_spriteList;
}
Run Code Online (Sandbox Code Playgroud)
然后在.mm文件中,我想做
CCSprite* newSprite = [/* cocos2d stuff here... */];
m_spriteList.push_back(newSprite);
Run Code Online (Sandbox Code Playgroud)
以上代码有效吗?它肯定是在C++中,但我不确定混合C++和Objective-C和Cocos2D.
当我尝试在Objective-C中使用C++代码时,我想在Objective-C头文件中将C++对象声明为成员变量.
假设我在test.h标头中声明了一个C++类:
Test{
};
Run Code Online (Sandbox Code Playgroud)
在Objective-C头文件中,我想做
#include "test.h"
#incude <boost/scoped_ptr.hpp>
#include <vector>
@interface MyClass : NSObject {
Test* m_testObjectPtr; // (1)
boost::scoped_ptr<Test> m_testOjbSmartPtr; // (2)
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,是(2)好吗?我可以像在C++代码中一样在Objective-C中使用智能指针吗?我可以假设在Test销毁MyClass对象时会调用类析构函数吗?
或者如果(2)在Objective-C++中不合适,(1)好吗?我需要手动调用
delete m_testObjectPtr的dealloc?
类模板中的模板构造函数 - 如何为第二个参数显式指定模板参数?
尝试显式指定构造函数2的模板参数时编译错误.如果我真的想要显式调用构造函数2,我应该怎么做?
请注意,当您想明确指定删除器类型时,boost :: shared_ptr的情况也是如此.
NB对于非构造函数foo(),显式指定工作正常.
注意我知道它没有为构造函数2明确指定第二个,因为模板参数推导通常只是工作正常,我只是很好奇如何明确指定它.
template<class T> class TestTemplate {
public:
//constructor 1
template<class Y> TestTemplate(T * p) {
cout << "c1" << endl;
}
//constructor 2
template<class Y, class D> TestTemplate(Y * p, D d) {
cout << "c2" << endl;
}
template<class T, class B>
void foo(T a, B b) {
cout << "foo" << endl;
}
};
int main() {
TestTemplate<int> tp(new int());//this one works ok call constructor 1 …Run Code Online (Sandbox Code Playgroud) 可能重复:
C++运算符%保证
在c ++ 98/03中
5.6-4
二元/运算符产生商,二元%运算符从第一个表达式除以第二个表达式得到余数.如果/或%的第二个操作数为零,则行为未定义; 否则(a/b)*b + a%b等于a.如果两个操作数都是非负的,那么余数是非负的; 如果没有,余数的符号是实现定义的.
在c ++ 11中:
5.6 -4
二元/运算符产生商,二元%运算符从第一个表达式除以第二个表达式得到余数.如果/或%的第二个操作数为零,则行为未定义.对于积分操作数,/运算符产生代数商,丢弃任何小数部分;如果商a/b在结果类型中可表示,则为(a/b)*b + a%b等于a.
正如您所看到的那样,为符号位定义的实现缺失了,它会发生什么?
基本上我想知道什么是c ++优化(/ O)和整个程序优化(/ GL).
会很感激深刻的解释.


谢谢
我有一个对象列表排序,我想找到一个对象的第一次出现和最后一次出现.在C++中,我可以轻松地使用std :: equal_range(或者只使用一个lower_bound和一个upper_bound).
例如:
bool mygreater (int i,int j) { return (i>j); }
int main () {
int myints[] = {10,20,30,30,20,10,10,20};
std::vector<int> v(myints,myints+8); // 10 20 30 30 20 10 10 20
std::pair<std::vector<int>::iterator,std::vector<int>::iterator> bounds;
// using default comparison:
std::sort (v.begin(), v.end()); // 10 10 10 20 20 20 30 30
bounds=std::equal_range (v.begin(), v.end(), 20); // ^ ^
// using "mygreater" as comp:
std::sort (v.begin(), v.end(), mygreater); // 30 30 20 20 20 10 10 10
bounds=std::equal_range (v.begin(), v.end(), 20, mygreater); …Run Code Online (Sandbox Code Playgroud) string foo() { return "hello"; }
int main()
{
//below should be illegal for binding a non-const (lvalue) reference to a rvalue
string& tem = foo();
//below should be the correct one as only const reference can be bind to rvalue(most important const)
const string& constTem = foo();
}
Run Code Online (Sandbox Code Playgroud)
std::string&从类型的临时类型无效初始化类型的非const引用std::stringstd::string到std::string &非const引用可以仅被绑定到一个左值&&,而是在演示代码中,我只是使用非const左值引用!可以用somone帮我解释一下VS2010的行为吗?这是一个错误!?谢谢
我需要在postgresql中获取一行最大时间戳的信息.以下是此问题的演示:
drop table Mytable cascade
create table MyTable (usr char(1), event_dt timestamp without time zone);
insert into mytable values ('A','01-JAN-2009 11:10:11');
insert into mytable values ('A','02-JAN-2009 11:10:22');
insert into mytable values ('B','02-JAN-2009 01:01:59' );
insert into mytable values ('C', '31-DEC-2008 02:02:02');
insert into mytable values ('D', '31-DEC-2008 03:03:03');
Run Code Online (Sandbox Code Playgroud)
如果我做
select max(event_dt) from (
select usr,event_dt from mytable where usr= 'A') as foo
Run Code Online (Sandbox Code Playgroud)
这是我需要的,但它只返回event_dt"2009-01-02 11:10:22"
我想要usr以及来自该行的event_dt.我该怎么做?
c++ ×8
boost ×2
standards ×2
c++03 ×1
c++11 ×1
java ×1
lower-bound ×1
lvalue ×1
max ×1
modulo ×1
objective-c ×1
optimization ×1
postgresql ×1
reference ×1
rvalue ×1
slice ×1
sql ×1
templates ×1
timestamp ×1
upperbound ×1
warnings ×1
xcode ×1