为什么重载的继承静态函数含糊不清?(Why are overloaded inherited static functions ambiguous?)
这是我尝试过的(函数“fun”必须是静态的):
#include<iostream> class A { public: static void fun(double x) { std::cout << "double" << std::endl; } }; class B { public: static void fun(int y) { std::cout << "int" << std::endl; } }; class C : public A, public B { }; int main(int argc, const char *argv[]) { double x = 1; int y = 1; C::fun(x); C::fun(y); return 0; }
并使用g ++(GCC)4.8.1 20130725(预发布),我收到以下错误:
main.cpp: In function 'int main(int, const char**)': main.cpp:27:5: error: reference to 'fun' is ambiguous C::fun(x); ^ main.cpp:12:21: note: candidates are: static void B::fun(int) static void fun(int y) { std::cout << "int" << std::endl; } ^ main.cpp:6:21: note: static void A::fun(double) static void fun(double x) { std::cout << "double" << std::endl;
所以我的问题是:如果我可以覆盖成员函数而不是静态函数,那怎么用C ++? 为什么在这种情况下不会超载? 我希望编译器将“fun”带入命名空间C ::然后进行名称修改并使用重载来区分C :: fun(int)和C :: fun(double)。
this is what I tried (the functions "fun" must be static):
#include<iostream> class A { public: static void fun(double x) { std::cout << "double" << std::endl; } }; class B { public: static void fun(int y) { std::cout << "int" << std::endl; } }; class C : public A, public B { }; int main(int argc, const char *argv[]) { double x = 1; int y = 1; C::fun(x); C::fun(y); return 0; }
and using g++ (GCC) 4.8.1 20130725 (prerelease), I got the following error:
main.cpp: In function 'int main(int, const char**)': main.cpp:27:5: error: reference to 'fun' is ambiguous C::fun(x); ^ main.cpp:12:21: note: candidates are: static void B::fun(int) static void fun(int y) { std::cout << "int" << std::endl; } ^ main.cpp:6:21: note: static void A::fun(double) static void fun(double x) { std::cout << "double" << std::endl;
So my question is: how come in C++ if I can override member functions, and not static functions? Why isn't overloading is not working in this scenario? I would expect the compiler to bring "fun" into the namespace C:: and then do name mangling and use overloading to distinguish C::fun(int) and C::fun(double).
原文:https://stackoverflow.com/questions/18869120
最满意答案
既然没有人回答,我猜不到。 这假设有一种简单的方法将查询字符串转换为JSON(有,它是
JSON.parse()
)。Since no one answered, I'm guessing none. This is assuming there is an easy way to convert query string to JSON (there is, it's
JSON.parse()
).
相关问答
更多-
import json import urlparse json.dumps(urlparse.parse_qs("a=1&b=2")) 产量 '{"a": ["1"], "b": ["2"]}' 这实际上比您的{"a":1, "b":2}更好,因为URL查询字符串可以合法地包含多次相同的密钥,即每个密钥有多个值。 import json import urlparse json.dumps(urlparse.parse_qs("a=1&b=2")) yields '{"a": ["1"], "b ...
-
尝试这种方法: https : //fiddle.jshell.net/koljada/53esaqLz/1/ var JSON_Object = [{ "SERIES": "ABC000123123", "SECTOR": "E", "INDUSTRY": "N31", "DURATION": "1A" }, { "SERIES": "ABC000123456", "SECTOR": "E", "INDUSTRY": "N11", "DURATION": "12" }, { ...
-
你想要一个单一的 dict对象,而不是它们的列表。 cat_dict = {} # 1 for cat in Category.query.all(): cat_dict[cat.id] = cat.name # 2 json_cat_dict = json.dumps(cat_dict) # 3 或者,(如@丹尼尔罗斯曼下面提到的)为了简洁,您可以将所有内容压缩成单个字典理解: cat_dict = {cat.id: cat.nam ...
-
这个字符串的格式是什么? 可以为该属性指定对象或字符串的值。 如果给它一个对象,那么它的键和值将被格式化为application/x-www-form-urlencoded数据(就像表单提交一样)。 如果给它一个字符串,它将是该字符串的任何东西 - 所以它可以是“无论使用它的代码的作者想要它”。 我看到这种格式的网址...... 这将是“无论作者想要什么”的情况。 注意; 和&可以在许多application/x-www-form-urlencoded解码库中互换使用。 这是HTML 4规范推荐的 。 这种 ...
-
$check = "title=hello&custLength=200&custWidth=300"; $keywords = preg_split("/[\s,=,&]+/", $check); $arr=array(); for($i=0;$i既然没有人回答,我猜不到。 这假设有一种简单的方法将查询字符串转换为JSON(有,它是JSON.parse() )。 Since no one answered, I'm guessing none. This is assuming there is an easy way to convert query string to JSON (there is, it's JSON.parse()).
从JSON动态创建Django> MySQL的查询字符串(Dynamically Create Query String for Django > MySQL from JSON)[2023-06-19]
而是字符串,创建一个字典,然后将其直接传递给mysqltable: mysqltable(**dictWithData) 当然你可以将字符串重新解析为字典,但这是无用的工作...... Instead string, create a dictionary, and then pass it directly to mysqltable: mysqltable(**dictWithData) Of course you can re-parse string onto dictionary, but t ...我首先使用for语句来迭代数组,因为你的json有索引和键值对的组合,而不是做foreach。 这里是: $query = ""; for($i = 0, $ctr = count($obj); $i < $ctr; $i++) { for($x = 0, $ctr_data = count($obj[$i]["data"]); $x < $ctr_data; $x++) { $query2 = array(); // After loop clean ...简单的JSON字符串查询(Simple JSON-String Query)[2022-05-02]
假设您能够提取服务器代码中的data 这是你如何使用org.json做到这org.json : JSONParser parser = new JSONParser(); JSONObject requestObj = (JSONObject) parser.parse(data); String name = (string)requestObj.get("name"); name = "Bruce Wayne"; 创建响应的代码可能如下所示: JSONObject response = new JSO ...谢谢你的回复。 我找到了解决这个问题的方法。 将Json写入请求流,标题为 postDataStream.Write(boundarybytes, 0, boundarybytes.Length); string header = string.Format("Content-Disposition: form-data; name=\"Key\"\r\n\r\n"); headerbytes = Encoding.Default.GetBytes(head ...相关文章
更多- error C2668: 'M' : ambiguous call to overloaded function
- 关于继承和static的小问题
- JavaFx Main中怎么绑定Java类中的一个static变量呢?
- 如何在runtime重载javascript alert函数
- Java 继承
- Java 重写(Override)与重载(Overload)
- Java静态变量的序列化
- Distributed RPC(分布式RPC)-Storm
- java 中静态变量的问题
- JPA高级映射(继承)
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)