我有一个关于受保护函数和多态的多重继承的问题.描述它很难,所以我希望它足够清楚.
说我有三个班:
class baseClass
{
protected:
virtual int function() = 0;
};
class derived_A:public baseClass
{
int function()
{
//implementation 1
};
};
class derived_B:public baseClass
{
int function()
{
//implementation 2
};
};
class derived_C:public derived_A, public derived_B
{
baseClass ** p_arr; //array of pointers of baseClass kind (polymorphism)
int x=0;
for (int i=0; i<arraySize; i++) // array size = many classes like derived_A, derived_B...
{
x = p_arr[i]->function(); //I already have function that builds this array
//it is …Run Code Online (Sandbox Code Playgroud) 我正在寻找c ++中的数据结构,我需要一个建议.
我有节点,每个节点都有unique_id和group_id:
1 1.1.1.1
2 1.1.1.2
3 1.1.1.3
4 1.1.2.1
5 1.1.2.2
6 1.1.2.3
7 2.1.1.1
8 2.1.1.2
Run Code Online (Sandbox Code Playgroud)
我需要一个数据结构来回答这些问题:
是否有可以回答这些问题的数据结构(插入和回答的复杂时间是多少)?或者我应该实施它?
我会很感激一个例子.
编辑:
在开始时,我需要构建这个数据结构.大部分动作都是按组ID阅读.插入会发生但不会再读.
时间复杂度比内存空间更重要
我遇到了问题gets.
目的是从用户那里获得输入,直到他点击'Enter'.
这是代码:
struct LinkedListNode* executeSection2()
{
char inputArr [3] = {'\0'};
struct LinkedListNode* newNode;
struct LinkedListNode* head = NULL;
gets (inputArr);
while (inputArr[0] != 0) // The user didn't press "Enter"
{
newNode=newLinkedListNode();
newNode->tree=newHuffmanNode(inputArr[0],atoi(inputArr+2));
head = addNode(&head, newNode);
gets (inputArr);
}
head = buildHuffmanTree(&head);
return head;
}
Run Code Online (Sandbox Code Playgroud)
似乎没问题,用户点击'Enter',代码从while出来,但在返回后,我收到错误信息:
变量'inputArr'周围的堆栈已损坏
我想我没有正确读取键盘输入.我会为一些指导感到高兴.
谢谢.
我正在尝试使用(key,value)构建一个堆,所以key是一个数字,value是一个字典。
import heapq
heap = []
dic = {'val_1': 'number_1', 'val_2': 'number_2', 'val_3': 'number_3'}
insetToHeap = (2,dic)
heapq.heappush(heap, insetToHeap)
Run Code Online (Sandbox Code Playgroud)
代码在上崩溃heappush。该元素的格式可能不正确。
编辑:
错误是:
TypeError:不可排序的类型:dict()<dict()
什么是插入堆(number,dic)元素的正确方法?
谢谢。
我正在尝试创建 makefile 并编译简单的示例,gtest但出现错误:
g++ main.o -o exampleOutput main.o:在功能
main': main.cpp:(.text+0x1e): undefined reference to测试中::InitGoogleTest(int*, char**)'collect2:错误:ld返回1退出状态make:***[输出]错误1
这是main.cpp:
#include <iostream>
#include "gtest/gtest.h"
using namespace std;
int main(int argc, char **argv)
{
cout << "This is test" << endl;
testing::InitGoogleTest(&argc, argv);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是生成文件:
INCLUDE = -I/usr/include/
LIBPATH = -L/usr/lib/
output: main.o
g++ main.o -o exampleOutput
main.o: main.cpp
g++ -c main.cpp $(INCLUDE) $(LIBPATH) -lgtest -lgtest_main -pthread
Run Code Online (Sandbox Code Playgroud)
(Gtest 的)头文件位于/usr/include/gtest
,lib 文件位于/usr/lib.
我究竟做错了什么?
谢谢。
我有一维数组,我需要计算它的平均值.
我试过了:
A = mean(mean(PSNRarr,2),2)
但是我收到了一个错误.
如果有人知道如何使它工作,那将是伟大的!
我有一个问题,它有点难以描述,所以请对我这么容易.
我有两个类,A和B,A类有一个私有成员 - 矢量:
class A
{
private:
struct complex
{
int x;
vector< int > y;
};
vector< complex > m_resultVector; // <---- the private member
public:
void getPointerToVector( vector< complex >::iterator it )
{
it = m_resultVector.begin();
}
};
Run Code Online (Sandbox Code Playgroud)
我需要从类B获取访问权限(仅读取),对此m_resultVector;,我可以编写一个get函数,但是m_resultVector非常长的向量,我不想将整个向量复制到新的向量,我想发送它的指针.也是重要的一部分 - 我需要B级不能改变的内容m_resultVector
class B
{
struct complex
{
int x;
vector< int > y;
};
void functionOf_B()
{
A class_A;
vector< complex >::iterator p_resultVector;
class_A.getPointerToVector(p_resultVector); // <------ compilation error here
// …Run Code Online (Sandbox Code Playgroud) 我对I,P,B帧及其时间戳有疑问.
我知道RTP数据包的时间戳假设是单调增加的.我也知道(纠正我,如果我错了)在h.264 B_5帧中可以在P_4帧之前发送但在(P_4然后是B_5)之后显示,因此解码器将使用B帧来解码P帧.
我有一个RTP\H.264流的pcap捕获,我可以看到时间戳增加\减少...而不是单调增加.
所以我的问题是什么值的RTP数据包(I,P,B帧)应该在h264传输上得到什么?
我很乐意对此事做一些澄清.
谢谢.
我正在尝试创建一个带有struct成员的类:
.h文件:
class A
{
public:
struct Result
{
int x;
UGraph G; <------ class definition
};
Result m_tempStructResult;
A:A(void);
void function();
}
Run Code Online (Sandbox Code Playgroud)
.cpp文件
A::A()
{
}
void A::function()
{
UGraph Graph(10); <---- object has to receive a value
...
//manipulations on Graph
...
m_tempStructResult.G = Graph;
}
Run Code Online (Sandbox Code Playgroud)
我得到的编译错误是:
error C2512: 'A::Result' : no appropriate default constructor available
Run Code Online (Sandbox Code Playgroud)
所以我猜的问题是缺少默认构造函数,所以我添加了这个:
struct Result
{
Result::Result(int graph_size=0) : G(graph_size){
}
int x;
UGraph G;
};
Run Code Online (Sandbox Code Playgroud)
问题解决了.
我的问题是,是否有另一种方法在类A的构造函数中启动类UGraph G?而不是在其成员结构中?
谢谢.
我遇到了这个问题:
给定两个线程和一个全局变量
var,两个线程运行相同的代码(C/C++代码):Run Code Online (Sandbox Code Playgroud)for(int i=0; i<20; i++) { var++; }
var线程执行结束时可能的值是什么?
如果每个线程var"正确" 递增- 我猜最大值将是40.
但最低价值呢?如何实施增量操作并实际完成?
注意:在有意增加操作中没有锁定(任何类型)(当然,正确的方法是锁定它 - 问题是出于教育目的).
我有一个编译错误,我不知道为什么.我在.h文件上有enum声明,而.cpp文件假设在stringToEnum()函数内部使用它
这是.cpp文件
#include "A.h"
A::A(void)
{
}
A::~A(void)
{
}
values A::stringToEnum (string inputString) {
if (inputString == "string1") return val1;
if (inputString == "string2") return val2;
}
Run Code Online (Sandbox Code Playgroud)
这是头文件
class A
{
public:
A(void);
~A(void);
private:
enum values{
val1,
val2,
val3,
val4
};
values stringToEnum (string inputString);
};
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C2143: syntax error : missing ';' before 'A::stringToEnum'
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int …Run Code Online (Sandbox Code Playgroud) 有没有办法删除所有内容container.Map(除了每个键使用删除)?并再次使用地图..
我试图把0:MyMap = 0但是MyMap在那个命令之后我不能再使用了.
谢谢.
我有一个很棒的项目.
我创建了一个新的独立 .dll项目,其中包含带有一些导出函数的原始项目(将原点.h和.cpp文件复制到新项目中).我从原始项目复制了所有lib依赖项和路径到那些库和其他包含文件.它的设置相同.
新程序编译但问题是,当我尝试运行代码时,我得到了错误信息:
The program can't start because xxx.dll is missing from your computer. Try reinstalling the program to fix this problem.
这xxx.lib是在Additional dependencies名单及其不是第一个:
Additional Dependencies: aaa.lib; bbb.lib; ccc.lib; xxx.lib, zzz.lib
我想VS发现了前三个,.lib否则我会得到一些错误信息..那么为什么不能找到xxx.lib呢?.lib同一文件夹中的所有文件..
谢谢.
c++ ×8
c ×2
matlab ×2
dictionary ×1
enums ×1
gets ×1
googletest ×1
h.264 ×1
heap ×1
inheritance ×1
makefile ×1
polymorphism ×1
protected ×1
python ×1
rtp ×1
vector ×1
video ×1