我有一个看起来像这样的结构:
sturct person
{
string surname;
person(string n) : surname(n) {};
}
Run Code Online (Sandbox Code Playgroud)
我需要重载operator<<的std::ostream和person.我写了这个函数:
std::ostream operator<<(std::ostream & s, person & os)
{
s << os.surname;
return s;
}
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
/usr/include/c++/4.6/bits/ios_base.h|788|error:'std :: ios_base :: ios_base(const std :: ios_base&)'是私有的|
/usr/include/c++/4.6/bits/basic_ios.h|64|error:在此上下文中
/usr/include/c++/4.6/ostream|57|note:这里首先要求合成方法'std :: basic_ios :: basic_ios(const std :: basic_ios&)'
我写了,我经常使用的应用程序pow功能的math.h库.我试图超载operator^以使取幂更容易和更快.我写了这段代码:
#include <iostream>
#include <math.h>
using namespace std;
int operator^(int, int); // line 6
int main(int argc, char * argv[]) { /* ... */ }
int operator^(int a, int n) // line 21
{
return pow(a,n);
}
Run Code Online (Sandbox Code Playgroud)
编译器(我在Linux上使用g ++)给我这些错误:
main.cpp:6:23:错误:'int operator ^(int,int)'必须有一个类的参数或枚举类型main.cpp:21:27:error:'int operator ^(int,int)'必须有一个类或枚举类型的参数
如何使(它在-> -> ...wxGrid之后继承)对象大小适合父级大小?我尝试了方法,但不起作用。
方法:wxScrollerWindowwxWindowswxPanelFitOnInit
bool MyApp::OnInit()
{
wxFrame * win = new wxFrame(NULL, -1, _T("App"), wxPoint(300,300), wxSize(400,300), wxDEFAULT_FRAME_STYLE);
wxPanel * panel = new wxPanel(win, -1);
wxGrid * grid = new wxGrid(panel, -1, wxPoint(5,5), wxSize(300,200));
grid->SetDefaultColSize(120);
grid->SetDefaultRowSize(55);
grid->SetRowLabelSize(55);
grid->SetColLabelSize(25);
grid->CreateGrid(2,6,wxGrid::wxGridSelectCells);
grid->Fit();
win->Show();
return true;
}
Run Code Online (Sandbox Code Playgroud)
MyApp继承后wxApp。