考虑一下代码:
#include <stdio.h>
class Base {
public:
virtual void gogo(int a){
printf(" Base :: gogo (int) \n");
};
virtual void gogo(int* a){
printf(" Base :: gogo (int*) \n");
};
};
class Derived : public Base{
public:
virtual void gogo(int* a){
printf(" Derived :: gogo (int*) \n");
};
};
int main(){
Derived obj;
obj.gogo(7);
}
Run Code Online (Sandbox Code Playgroud)
得到此错误:
>g++ -pedantic -Os test.cpp -o test test.cpp: In function `int main()': test.cpp:31: error: no matching function for call to `Derived::gogo(int)' test.cpp:21: note: candidates are: virtual …
恕我直言,OOPS,设计模式是有道理的,我已经能够实际应用它们.
但是当谈到 Modern C++类的"泛型编程/元编程"时,我感到很困惑.
- 这是一种新的编程/设计范式吗?
- 它仅限于"图书馆开发"吗?如果没有,那么设计/编码情况需要使用元编程/泛型编程.
- 使用模板意味着我正在进行通用编程吗?
我在这个主题上搜索了很多,但没有完全掌握大图.另见这篇文章.
在阅读了这里的讨论之后,到目前为止,我确信(可能仍然不正确):
a)通用编程和元编程是两个不同的概念.
我正在阅读如何像计算机科学家一样思考,这是"Python编程"的入门文本.
我想澄清*应用于列表时multiply operator()的行为.
考虑函数make_matrix
def make_matrix(rows, columns):
"""
>>> make_matrix(4, 2)
[[0, 0], [0, 0], [0, 0], [0, 0]]
>>> m = make_matrix(4, 2)
>>> m[1][1] = 7
>>> m
[[0, 0], [0, 7], [0, 0], [0, 0]]
"""
return [[0] * columns] * rows
Run Code Online (Sandbox Code Playgroud)
实际输出是
[[0, 7], [0, 7], [0, 7], [0, 7]]
Run Code Online (Sandbox Code Playgroud)
make_matrix的正确版本 是:
def make_matrix(rows, columns):
"""
>>> make_matrix(3, 5)
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, …Run Code Online (Sandbox Code Playgroud) 我有Class声明一个方法但没有实现它.该方法不是虚函数.在相应的cpp文件中,我没有找到相同方法的定义.定义了类中声明的所有其他方法.
我编译了代码,它很好.我的印象是cpp必须强制声明已声明方法的定义.
如果有人可以详细说明同意,请感谢.我正在使用VS2010的cl编译器.
由于Python 2.6向后兼容2.52,所以有人成功地将它与Google app Engine(正式支持2.52)一起使用.
我知道我应该自己尝试一下.但我是一个python和web-app新蜜蜂,对我来说,安装和配置是最难的部分,同时开始在这个领域的新东西.(....我在同一时间自己尝试......)
谢谢
也许这是非常基本的,但我都很困惑.我有一个简单的html页面,包含许多部分(div).我在javascript中有一个包含html标签的字符串.代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var str1="<html><body><div id='item1'><h2>This is a heading1</h2><p>This is a paragraph1.</p></div><div id='item2'><h2>This is a heading2</h2><p>This is another paragraph.</p></div><div id='lastdiv'>last</div></body></html>";
</script>
</head>
<body>
<div id="title1"></div>
<div id="new1"></div>
<div id="title2"></div>
<div id="new2"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想提取html标签的内容(来自javascript中的字符串),并在我的html页面中显示所需部分中的内容.
即我想在"这是一个段落1"中显示"这是一个标题1" <div id="title1">.显示在<div id="new1">第二对标签中并与之相同.
我需要所有这些只在客户端工作.我试图使用HTML DOM getElementByTagName方法,它变得太复杂了.我对jquery知之甚少.我很困惑.我不明白该怎么做.你能指导我使用什么--javascript或jquery以及如何使用它?有没有办法从字符串中识别并迭代它?
如何从str1中提取"This is heading1"(和html标签中包含的类似内容)?我不知道这些索引因此无法在javascript中使用substr()或substring()函数.
我有一个使用visual studio 2003构建的旧项目,最近我用vs2005重新编译了它.但是,在运行时,我收到以下错误:
列表迭代器不可递增
我跟踪程序到这个函数:
void InputQueue::update()
{
list<PCB>::iterator iter;
list<PCB>::iterator iterTemp;
for(iter = begin(); iter != end(); iter++)
{
if(iter->arrivalTime == 0)
{
ReadyQueue::getInstance()->add(*iter);
iterTemp = iter;
iter++;
erase(iterTemp);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不是C++专家,这就是VS调试器给我的.有人可以向我解释问题是什么吗?
谢谢
有人可以向我解释以下编译器错误:
struct B
{
};
template <typename T>
struct A : private T
{
};
struct C : public A<B>
{
C(A<B>); // ERROR HERE
};
Run Code Online (Sandbox Code Playgroud)
指示行的错误是:
test.cpp:2:1: error: 'struct B B::B' is inaccessible
test.cpp:12:7: error: within this context
Run Code Online (Sandbox Code Playgroud)
究竟什么是难以接近的,为什么?
c++ inheritance templates compiler-errors private-inheritance
首先,抱歉模糊的标题.
假设我有以下几组:
s1 = ( x1, y1 )
s2 = ( x2 )
Run Code Online (Sandbox Code Playgroud)
m1 = ( x1, y1, y2 )
m2 = ( x1 )
m3 = ( x1 , x2 )
Run Code Online (Sandbox Code Playgroud)
对于每个集合Group 1- 调用集合s,我需要找到集合Group 2- 调用它m- 这m是它的一个子集s.
所以,对于我的例子,答案是:
s1 -> m2
s2 -> nothing
Run Code Online (Sandbox Code Playgroud)
现在,我正在存储值std:set,但如果需要,我可以更改它.此外,集合可能会变大,因此算法需要高效.现在我有一种蛮力的方法,我并不完全满意.
有什么建议?
c++ ×7
templates ×3
python ×2
algorithm ×1
compilation ×1
html ×1
inheritance ×1
iterator ×1
javascript ×1
jquery ×1
linker ×1
list ×1
overriding ×1
polymorphism ×1
set ×1
stl ×1
subset ×1