对于我的异常类,我有一个具有多个参数(...)的构造函数,它在windows下工作正常,但是在linux下它编译得很好但是拒绝链接到它.
为什么这不能在linux下运行?
这是一个例子:
class gcException
{
public:
gcException()
{
//code here
}
gcException(uint32 errId, const char* format = NULL, ...)
{
//code here
}
}
enum
{
ERR_BADCURLHANDLE,
};
Run Code Online (Sandbox Code Playgroud)
.
编辑
所以,当我这样称呼时:
if(!m_pCurlHandle)
throw gcException(ERR_BADCURLHANDLE);
Run Code Online (Sandbox Code Playgroud)
我得到这个编译错误:
error: no matching function for call to ‘gcException::gcException(gcException)’
candidates are: gcException::gcException(const gcException*)
gcException::gcException(gcException*)
gcException::gcException(gcException&)
Run Code Online (Sandbox Code Playgroud) 在我的一个iPhone应用程序中,我需要有条件地将变量参数发送到操作表.即
if(condition1)
otherButtonTitles = @"Button1", @"Button2", nil
else
otherButtonTitles = @"Button3", @"Button4", nil
UIActionSheet *mediaActionsSheet = [[UIActionSheet alloc] initWithTitle: nil
delegate: self
cancelButtonTitle: @"Cancel"
destructiveButtonTitle: nil
otherButtonTitles: otherButtonTitles];
Run Code Online (Sandbox Code Playgroud)
这样做的语法是什么?应如何定义otherButtonTitles的数据类型?
提前致谢.
此致,Deepa
void AppBuf(message_id_type msgID, int32 numPairs, va_list va)
{
int32 len = va_args(va, int32);
....
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在windows(32位和64位)以及linux 32位编译器上运行得非常好.对于以上所有,'len'的值为10.
但是在linux 64位(x86_64 GNU/Linux)上,我得到了一个非常大的值len(50462976),这会使代码的其余部分混乱并在崩溃中结束.
我曾经读过linux 64位编译器中的某些内容已经发生了变化,va_lists但我无法理解这一变化,所以我无法解决我的问题.
有人可以帮我解决这个问题吗?
谢谢.
晴朗
好的,以下是导致这一点的整个代码的详细信息:有人可以帮忙吗?提前致谢.
调用堆栈:
AppendBuffers(int msgID = 0x00000001,int numPairs = 0x00000001,char*va = 0x0007fcb0){注意:这是上面提到的问题所在(长度=非常大)}
LogMsg(int msgID = 0x00000001,int numPairs = 0x00000001,char*arguments = 0x0007fcb0)
LogMsgBuffersV(int msgID = 0x00000001,int numPairs = 0x00000001,char*arguments = 0x0007fcb0)
LogMsgBuffersV(int msgID = 0x00000001,int numPairs = 0x00000001,char*arguments = 0x0007fcb0)
LogMsgBuffers(int msgID = 0x00000001,int numPairs = 0x00000001,...)
实际代码:
void LogMsgBuffers(message_id_type …Run Code Online (Sandbox Code Playgroud) 我有一个功能
AddSprintf(char* , ... )
Run Code Online (Sandbox Code Playgroud)
如果有人在没有两个参数的情况下调用它,我想编译时错误.目前如果有人打电话的话
AddSprintf("hello")
Run Code Online (Sandbox Code Playgroud)
有用.但我想禁用这样的呼叫.有没有办法使用g ++我可以强制传递参数?
假设这段代码:
public class Test{
public static void main(String[] args) {
Test.testInt(new int[]{2,3});
Test.testInteger(new Integer[]{2,3});
}
public static void testInt(Object... elements){
System.out.println(elements[0] instanceof int[]);
}
public static void testInteger(Object... elements){
System.out.println(elements[0] instanceof Integer);
}
}
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,一个人都希望有一个包含2和3的一维数组.所以预期的输出应该是第一眼:
false
true
Run Code Online (Sandbox Code Playgroud)
惊喜!实际输出是:
true
true
Run Code Online (Sandbox Code Playgroud)
本次更新的最新消息:
实际上,这不是一个好问题,因为我没有意识到这种情况符合Var-args规则.
总而言之,即使Var-args是参数,int []数组也不能自动装箱到Integer []; 没有特殊的待遇.
怎样public static void main(String args[])的String args[]实现?它被实现为varargs?
我问这个是因为args.length只提供了传递的参数数量,这意味着它没有在任何地方定义String args[] = new String[30].这个数组是如何实现的?
我需要%%在格式字符串中使用才能写出这样的%字符:
printf("%%");
Run Code Online (Sandbox Code Playgroud)
我试图在我的变量参数列表函数中执行此操作.格式符做工精细,例如%d,%s等等.但是,当我尝试写%使用字符%%,这是行不通的.为什么有解决方案?
void foo(LPCSTR sFrmtStr, ...)
{
char buffer[4096] = { 0 };
va_list argList;
va_start(argList, sFrmtStr);
vsprintf(buffer, sFrmtStr, argList);
va_end(argList);
printf(buffer);
}
Run Code Online (Sandbox Code Playgroud) 我只是想用一个可变数量的参数编写一个非常简单的函数,所以我可以为一个赋值编写一个类似于printf的函数.看完文档之后,va_list我不确定为什么这段代码会一直给我运行时错误:
这是我的代码:
void print(string sOne , ...);
void main()
{
print("first string", "second string", "third String");
system("pause");
}
void print(string sOne , ...)
{
va_list arguments;
va_start(arguments, sOne);
while ((va_arg(arguments, int)) != 0)
{
string printString = va_arg(arguments, string);
cout << printString;
}
va_end(arguments);
}
Run Code Online (Sandbox Code Playgroud) 给出以下辅助函数
template <typename ... Ts>
auto f(Ts&& ... args) {}
template <typename T>
auto g(T x) { return x; }
Run Code Online (Sandbox Code Playgroud)
1)我们像往常一样扩展模板参数包.
template <typename ... Ts>
void test1(Ts&& ... args)
{
f(args...);
}
Run Code Online (Sandbox Code Playgroud)
2)这里扩展...发生在函数调用之后g().这也是合理的,因为g()每个人都会调用它args:
template <typename ... Ts>
void test2(Ts&& ... args)
{
f(g(args)...);
}
Run Code Online (Sandbox Code Playgroud)
3)我期望的逻辑相同test3(Is, args...)...,但没有.你必须写test3(Is..., args...):
template <typename ... Ts>
void test3(size_t i, Ts&& ... args)
{
f(args...);
}
template <typename ... Ts>
void …Run Code Online (Sandbox Code Playgroud) 我的目标是在初始化包含所述对象的PriorityQueue时创建一个捕获2个或更多对象的varargs的函数.
相关代码是:
case class Topic(topic: String, usageFrequency: Long = 1)
object FreqOrdering extends Ordering[Topic] {
def compare(a: Topic, b:Topic) = -(a.usageFrequency compare b.usageFrequency)}
def initPriQu(a : Topic, b: Topic, c: Topic*): PriorityQueue[Topic] = {
return PriorityQueue(a,b,c)(FreqOrdering)}
Run Code Online (Sandbox Code Playgroud)
sbt(Scala 2)中的错误:
[错误]实测值:TopicTrenderInit.FreqOrdering.type
[错误]需要:scala.math.Ordering [等于]
[错误]注:TopicTrenderInit.Topic <:等于(和TopicTrenderInit.FreqOrdering.type <:scala.math.Ordering [TopicTrenderInit .Topic]),但特性排序在类型T中是不变的.
[错误]您可能希望调查通配符类型,如_ <: Equals.(SLS 3.2.10)
[错误]返回PriorityQueue中(A,B,C)(FreqOrdering)
[错误] ^
[错误] /home/aaron-laptop/Documents/Scala/topic_trender100/src/main/scala/main.scala :48:25:类型不匹配;
[错误]实测值:scala.collection.mutable.PriorityQueue [等于]
[错误]需要:scala.collection.mutable.PriorityQueue [TopicTrenderInit.Topic]
[错误]注:等于>:TopicTrenderInit.Topic,但类PriorityQueue是不变类型A.
[错误]您可能希望调查通配符类型,例如_ >: TopicTrenderInit.Topic.(SLS 3.2.10)
[错误]返回PriorityQueue(a,b,c)(FreqOrdering)
没有'*'表示vararg一切正常,没有错误.我认为最糟糕的是困扰我所需要的:scala.math.Ordering [Equals]错误我看到了.我还阅读了一篇关于模式匹配的文章,但我觉得我必须阅读更多内容才能理解实现.这里发生了什么?
谢谢.