考虑一对两个源文件:接口声明文件(*.h或*.hpp)及其实现文件(*.cpp).
让*.h文件如下所示:
namespace MyNamespace {
class MyClass {
public:
int foo();
};
}
Run Code Online (Sandbox Code Playgroud)
我在源文件中看到了两种不同的使用命名空间的做法:
*.cpp 练习#1:
#include "MyClass.h"
using namespace MyNamespace;
int MyClass::foo() { ... }
Run Code Online (Sandbox Code Playgroud)
*.cpp 练习#2:
#include "MyClass.h"
namespace MyNamespace {
int MyClass::foo() { ... }
}
Run Code Online (Sandbox Code Playgroud)
我的问题:这两种做法之间是否有任何差异,哪一种被认为比另一种更好?
美好的一天!
在他的"有效STL"中,Scott Meyers写道
第三种方法是使用迭代器的有序容器中的信息迭代地将列表元素拼接到您希望它们所在的位置.正如您所看到的,有很多选项.(第31项,第2部分)
有人可以这样解释我吗?
更多文字(了解背景):
算法sort,stable_sort,partial_sort和nth_element需要随机访问迭代器,因此它们只能应用于向量,字符串,deques和数组.在标准关联容器中对元素进行排序是没有意义的,因为这样的容器使用它们的比较函数始终保持排序.我们可能希望使用sort,stable_sort,partial_sort或nth_element但不能的唯一容器是list,并且list通过提供其排序成员函数来进行补偿.(有趣的是,list :: sort执行稳定的排序.)如果要对列表进行排序,则可以,但如果要对列表中的对象使用partial_sort或nth_element,则必须间接执行.一种间接方法是将元素复制到具有随机访问迭代器的容器中,然后将所需的算法应用于该容器.另一种方法是创建一个list :: iterators的容器,在该容器上使用该算法,然后通过迭代器访问列表元素.第三种方法是使用迭代器的有序容器中的信息迭代地将列表元素拼接到您希望它们所在的位置.正如您所看到的,有很多选项.
我是iOS编程的新手,遇到了一个问题.
做了什么:
我创建了iOS应用程序.最初它有main.m,AppDelegate.h,AppDelegate.m和一些其他通常创建的支持文件(不带代码).
然后我用接口(LoginView.xib)手动创建了XIB文件,并手动添加了LoginViewController.h和LoginViewController.m来控制XIB.
为LoginViewController.h添加了插座.
毕竟我设置了文件的所有者类(LoginViewController)并在XIB和LoginViewController.h之间建立了连接.
问题描述:
我需要在应用程序启动时立即显示实例化登录视图控制器并显示登录视图.
我尝试了几次尝试并阅读了十几个论坛帖子,但没办法.除了白色窗口背景外没有显示任何内容.我该怎么做对吗?
参考代码:
LoginViewController.h
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController
{
IBOutlet UIView *_loginView;
IBOutlet UITextField *_tfLogin;
IBOutlet UITextField *_tfPassword;
IBOutlet UIButton *_btnLoginToSystem;
}
- (IBAction)attemptLogin:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
LoginViewController.m
#import "LoginViewController.h"
@interface LoginViewController ()
@end
@implementation LoginViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- …Run Code Online (Sandbox Code Playgroud) 我最近花了几个小时tkinter在我的pyenvPython 安装 (macOS)上制作和空闲工作。
你为什么在这里?
pyenv在 macOS 上管理 Python 版本,并且tkinter模块工作)怎么了?
您会收到以下错误之一:
Python may not be configured for Tk 在 import tkinterimport _tkinter # If this fails your Python may not be configured for TkRuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)ModuleNotFoundError: No module named '_tkinter'谁知道在哪里可以找到有关.dictionary格式的信息以及如何手动读取格式?
我知道.dictionary是一个目录,但我不知道如何处理它的内容.
我想手动阅读.
我有一个项目.该项目包括2个应用程序:iOS和Android.应用程序类似(对不同的操作系统执行相同操作).当且仅当两个应用程序都交付时,该项目才被视为已完成.
然后,应用程序可以独立发展(在版本意义上,例如,可能有1.3版iOS版和1.1版Android版).
我使用JIRA进行项目管理.
我想知道如何更好地与JIRA组织这个项目.
选项#1: 为它创建一个项目和一个汇合空间.为每个功能创建一个用户素材,然后在iOS和Android内部创建子任务(重复的子任务).看起来很乱.而且看起来很难识别哪个应用程序遇到了麻烦,因为整个项目都在同一个底池中.
选项#2: 创建两个项目(适用于iOS和Android)和一个汇合空间.然后为每个项目创建故事(重复的故事).看起来更易于管理,但故事重复看起来很糟糕.
请帮忙.
拥有以下代码:
#include <iostream>
#include <set>
#include <string>
#include <functional>
using namespace std;
class Employee {
// ...
int _id;
string _name;
string _title;
public:
Employee(int id): _id(id) {}
string const &name() const { return _name; }
void setName(string const &newName) { _name = newName; }
string const &title() const { return _title; }
void setTitle(string const &newTitle) { _title = newTitle; }
int id() const { return _id; }
};
struct compEmployeesByID: public binary_function<Employee, Employee, bool> {
bool operator()(Employee const …Run Code Online (Sandbox Code Playgroud) 它可能看起来很愚蠢,但我想知道为什么下面的代码会产生CS0106编译时错误:
error CS0106: The modifier 'readonly' is not valid for this item
代码:
class MyClass
{
private readonly int _value
{
get
{
if (_value < 0)
return -1 * _value;
return _value;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的理解中,我在内部没有任何错误,get因为我只读了价值.我同意readonly从逻辑的角度来看,对属性获取者的计算看起来很尴尬.
内部PS代码get没有实际意义 - 它只是一个"读取内容的东西_value"
UPDATE
总之,最初我认为使用readonly关键字创建只读属性是相当逻辑的.我错过了readonlyMicrosoft文档提供的有关属性的主要内容:
readonly关键字是一个可以在字段上使用的修饰符.
代码如下:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct A {
A(int i = -1): i_(i) {
wcout << "Constructor: i = " << i_ << endl;
}
A(A const &a) {
wcout << "Copy constructor: i = " << i_ << " a.i = " << a.i_ << endl;
*this = a;
}
~A() { wcout << "Destructor: i = " << i_ << endl; }
A &operator=(A const& a) {
wcout << "Copy assignment operator: i …Run Code Online (Sandbox Code Playgroud) 拥有以下代码:
template<typename T, typename OutStream = std::ostream> struct print {
OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const {
outStream << toPrint;
return outStream;
}
};
Run Code Online (Sandbox Code Playgroud)
这个电话是错误的:
print<int>(2);
Run Code Online (Sandbox Code Playgroud)
错误信息:
1>main.cpp(38): error C2440: '<function-style-cast>' : cannot convert from 'int' to 'print<T>'
1> with
1> [
1> T=int
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
Run Code Online (Sandbox Code Playgroud)
这个电话没有错误:
print<int> intPrinter;
intPrinter(2);
Run Code Online (Sandbox Code Playgroud)
我可以在没有实例化的情况下以某种方式使用函数对象吗?我不能在这里使用模板功能,因为我需要部分专业化功能.
请考虑以下代码:
//#import <Foundation/Foundation.h>
int main(int argc, const char *argv[]) {
@autoreleasepool {
NSLog(@"Hello World!");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么它可以建立和运行?w/out基金会标题!
对我来说,C编译器编译这个代码w/out标题即w/out DECLARATIONS仍然很奇怪.奇怪的是,编译器以某种方式将我的函数与已编译的代码(Foundation)匹配并成功.是否有一些指向C标准的链接,它将解释我如何解析被识别为函数且以前从未声明过的令牌?
请解释!!
更新:这些不是由于预编译的标头
谢谢!但不是.我通过以下方式测试它 - 只需在vi编辑器中键入Hello World代码并将其保存为main.m文件.比用Terminal的clang编译它.电子邮件只有1个警告就可以了:
main.m:8:9: warning: implicitly declaring library function 'NSLog' with type 'void (id, ...)' NSLog(@"Hello World!");
^ main.m:8:9: note: please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLog'
1 warning generated.
Run Code Online (Sandbox Code Playgroud)
更新:只需逐步附加所有图像:

主题:简单的基于 C++ Win32 API 的单窗口应用程序。请参阅下面的代码。计算机是 MacBook Retina,本地安装了 Windows 10。
问题:标题栏(窗口的非客户区域)中的最小化/最大化/关闭按钮在鼠标悬停事件上表现不正确。每个按钮仅在鼠标光标移动时突出显示,而按钮应一直突出显示,直到鼠标指针离开按钮区域。
问题是:有什么问题?Win10清单?
编码:
#include <Windows.h>
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR msgGreeting[] = _T("Hello World from MyWindowsApp!");
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 10, 10, msgGreeting, (int)_tcsclen(msgGreeting));
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR …Run Code Online (Sandbox Code Playgroud) 请帮我理解以下问题.
看下面的代码示例:
#include <iostream>
class Shape {
public:
virtual wchar_t *GetName() { return L"Shape"; }
};
class Circle: public Shape {
public:
wchar_t *GetName() { return L"Circle"; }
double GetRadius() { return 100.; }
};
int wmain() {
using namespace std;
auto_ptr<Shape> aS;
auto_ptr<Circle> aC(new Circle);
aS = aC;
wcout << aS->GetName() << L'\t' << static_cast<auto_ptr<Circle>>(aS)->GetRadius() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么我不被允许这样做:
static_cast<auto_ptr<Circle>>(aS)->GetRadius()
Run Code Online (Sandbox Code Playgroud)
编译器(MSVCPP 11):
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory(911): error C2440: 'initializing' : cannot convert from 'Shape *' …Run Code Online (Sandbox Code Playgroud) c++ ×6
ios ×2
macos ×2
objective-c ×2
stl ×2
android ×1
appdelegate ×1
auto-ptr ×1
c ×1
c# ×1
casting ×1
compilation ×1
const ×1
constructor ×1
destructor ×1
format ×1
header-files ×1
highdpi ×1
invariants ×1
jira ×1
list ×1
namespaces ×1
project ×1
pyenv ×1
python ×1
python-idle ×1
set ×1
sorting ×1
std ×1
templates ×1
tkinter ×1
uiview ×1
vector ×1
win32gui ×1
winapi ×1
windows-10 ×1