尝试使用当前签名在g ++中编译我的代码时出错:
cannot declare member function static void Foo::Bar(std::ostream&, const Foo::Node*) to have static linkage
Run Code Online (Sandbox Code Playgroud)
我的问题是双重的:
在使用C++时,签名一直是我的死
编辑:这是类头文件,以及:
class Foo {
public:
Foo();
~Foo();
bool insert(const Foo2 &v);
Foo * find(const Foo2 &v);
const Foo * find(const Foo2 &v) const;
void output(ostream &s) const;
private:
//Foo(const Foo &v);
//Foo& operator =(const Foo &v);
//Not implemented; unneeded
struct Node {
Foo2 info;
Node *left;
Node *right;
};
Node * root;
static bool insert(const Foo2 &v, Node *&p);
static void …
Run Code Online (Sandbox Code Playgroud) 我知道数组是动态创建的,并且提前创建它们并不是必需的,但是如何用2D数组做到这一点?一样的方法?
(for$j)
{
for($i)
{
$array[j][i] = "data";
}
}
Run Code Online (Sandbox Code Playgroud)
那样的东西?当然,显然是真正的循环.
我看起来无济于事,我担心这可能是一个简单的问题,没有人敢问它.
可以从一行中的标准输入输入多个东西吗?我是说这个:
float a, b;
char c;
// It is safe to assume a, b, c will be in float, float, char form?
cin >> a >> b >> c;
Run Code Online (Sandbox Code Playgroud) 这是功课
我正在为我的C++类实现一个链表类,而复制构造函数对我来说非常困惑.
链表由称为Elems的结构组成:
struct Elem
{
int pri;
data info;
Elem * next;
};
Elem * head;
Run Code Online (Sandbox Code Playgroud)
info是一个单独的自定义类,存储在Elem中.
复制构造函数的签名是:
linkedList::linkedList( const linkedList &v )
Run Code Online (Sandbox Code Playgroud)
我遇到的问题主要是采用我的逻辑并实际将其编写为代码.
我的总体想法是:
这是一般的想法吗?
任何帮助都会很棒.记住,这是作业,所以请不要直接回答!
感谢您的时间
================================================== ================================================== ================================================== ==============
感谢大家的时间!
我想我已经弄清楚了:
//Copy Constructor
LinkedList::LinkedList( const LinkedList &v )
{
Elem * p1 = 0;//current
Elem * p2 = 0;//next
if( v.head == 0 )
head = 0;
else
{
head = new Elem;
head …
Run Code Online (Sandbox Code Playgroud) 我想在继续之前提及我已经查看了在本网站以及其他网站上提出相同问题的其他问题.我希望我能得到一个好的答案,因为我的目标是双重的:
在主菜上:
据我所知,到目前为止,哈希表是一个列表数组(或类似的数据结构),希望最佳地尽可能少地进行冲突,以保持其受到称赞的O(1)复杂性.以下是我目前的流程:
所以我的第一步是创建一个指针数组:
Elem ** table;
table = new Elem*[size];//size is the desired size of the array
Run Code Online (Sandbox Code Playgroud)
我的第二步是创建一个散列函数(一个非常简单的函数).
int hashed = 0;
hashed = ( atoi( name.c_str() ) + id ) % size;
//name is a std string, and id is a large integer. Size is the size of the array.
Run Code Online (Sandbox Code Playgroud)
我的第三步是创建一些东西来检测碰撞,这是我目前所处的部分.
这是一些伪代码:
while( table[hashedValue] != empty )
hashedValue++
else
put in the list at that index.
Run Code Online (Sandbox Code Playgroud)
它相对不优雅,但我仍处于"这是什么"阶段.忍受我.
还有别的事吗?我错过了什么或做错了吗?
谢谢
我试图提高我对C++的理解,尤其是指针算法.我经常使用atoi,但我很少考虑它是如何工作的.看看它是如何完成的,我主要理解它,但有一件事我很困惑.
以下是我在网上找到的解决方案示例:
int atoi( char* pStr )
{
int iRetVal = 0;
if ( pStr )
{
while ( *pStr && *pStr <= '9' && *pStr >= '0' )
{
iRetVal = (iRetVal * 10) + (*pStr - '0');
pStr++;
}
}
return iRetVal;
}
Run Code Online (Sandbox Code Playgroud)
我认为我很难掌握atoi过去的主要原因是角色的比较方式."while"语句在字符存在时说,并且字符小于或等于9,并且它大于或等于0然后执行操作.这句话对我说了两件事:
在我调查之前,我想我下意识地知道它,但我从未真正想过它,但是'5'字符比'6'字符"小",就像5小于6一样,所以你可以比较字符作为整数,基本上(对于这个意图).
编辑:我不知道*pStr - '0'部分会做什么.
任何理解这些观察结果的帮助都会非常有帮助!谢谢!
我有太多空白的问题.这是我的数据字段的图片,其中占位符表示可能的最大数字计数.
如您所见,在最后一个"P"之后,这些值会超出图表的范围.虽然我可以增加整个表格的大小(目前是文本宽度),但这对我来说是一个糟糕的设计选择.我在想的是利用所有浪费的白色空间.我不知道该怎么办.
当我有所有单个数字值时,表格看起来很完美.我希望增加的数字大小"消耗"空白区域,然后强制表格超出其定义的界限.我希望使用extracolsep没有参数会删除空格,但遗憾的是没有.
我当前的递归函数在某种程度上起作用,但是当它回到堆栈时会自行消失.
void Graph::findPath( Room * curRoom )
{
if( curRoom -> myNumber == 0 )
{
cout << "Outside.\n";
//Escape the recursion!
}
else
{
curRoom -> visited = true;
if( curRoom -> North -> visited == false )
{
escapePath[ _index ] = "North";
cout << "_index: " << _index << "\n";
++_index;
findPath( curRoom -> North );
cout << "_index: " << _index << "\n";
escapePath[ _index ] = "";
--_index;
}
if( curRoom -> East -> visited …
Run Code Online (Sandbox Code Playgroud) 我目前正在创建一个PHP脚本来绘制来自数据库的一堆数据,将其排列成文本文件,然后运行GNUPlot脚本来生成图形.我已经完成了所有这些工作,现在我需要做的就是删除我不再需要的文本文件.
我一直在尝试的是从另一个论坛上的另一个主题得到的:
foreach( glob('US_A.2.6.*') as $file )
{
unlink($file);
}
Run Code Online (Sandbox Code Playgroud)
然而,问题是它不起作用.这些文件具有复杂的结束名称:
和更多.
我目前关于如何输出我的二叉树的实现让我在g ++中遇到错误
Conditional jump or move depends on uninitialised value(s)
Run Code Online (Sandbox Code Playgroud)
我目前的实施是:
void Foo::output(ostream &s, const Node *p)
{
if( p )
{
output( s , p -> left );
s << p -> info;
output( s , p -> right );
}
}
Run Code Online (Sandbox Code Playgroud)
Node是一个基本结构,带有左右指针和一个整数信息变量.
ostream只是cout
错误信息是非常直接的,它不喜欢我让它"跑掉".
我的问题是双重的:
谢谢