我正在写一些C代码,并注意到我认为是一个错误,但事实并非如此.我有以下类型声明声明.
const fee;
Run Code Online (Sandbox Code Playgroud)
但是,它最初没有被删除,因为编译器和我没有抓住它.所以我很好奇为什么C允许这个以及什么是默认类型.
我正在看某人对项目的想法.这个人希望有两个程序通过管道进行通信.这是我的问题.是否可以创建两个通过命令行管道相互通信的程序?
我想在程序的主线程上使用 STAThread 属性。但是,Visual Studio 表示找不到它。我已经尝试引用必要的程序集并使用正确的命名空间,但它只是找不到它。
编辑:
在使用 ApartmentState 到 STA 手动创建线程后,我已经能够成功工作。我认为这相当于设置线程,无论是主线程,但不完全是因为我正在创建另一个线程。任何人都有其他方法可以做到这一点。
这是代码:
void threadStart ()
{
Application::Run (gcnew GraphicsForm());
}
[System::STAThread] // This will not work!
int main(array<System::String ^> ^args)
{
Thread ^t = gcnew Thread(gcnew ThreadStart (threadStart));
t->ApartmentState = ApartmentState::STA;
t->Start();
return 0;
}
Run Code Online (Sandbox Code Playgroud) template <class T>
Vector<T>::Vector() : _size_(0){
this->_capacity_ = 10;
buffer = new T[this->_capacity_];
}
template <class T>
Vector<T>::Vector(unsigned int s) {
this->_size_ = s;
this->_capacity_ = _size_;
this->buffer = new T[this->_capacity_];
init(0, this->_size_);
}
template <class T>
Vector<T>::Vector(unsigned int s, const T &initial){
this->_size_ = s;
this->_capacity_ = s;
this->buffer = new T[this->_capacity_];
init(0, s, initial);
}
Run Code Online (Sandbox Code Playgroud)
我的代码经常使用this关键字.在没有this关键字的情况下,在类中调用成员函数而不是直接访问它是一种良好的做法吗?如果我总是调用成员函数来访问成员变量,它会产生开销吗?C++实现做了什么?
如何重新设置解除引用运算符?宣言会是什么样子?我正在创建一个列表类,但我在解除引用运算符时遇到问题.
这是我重载dereference运算符的函数
template <typename T>
T List_Iterator<T>::operator *(){
return current_link->value;
}
Run Code Online (Sandbox Code Playgroud)
这是我的迭代器类中的数据成员
private:
/* Data Members */
Link<T>* current_link;
Run Code Online (Sandbox Code Playgroud)
这是我的链接类
protected:
T value;
Run Code Online (Sandbox Code Playgroud) 这是我的班级。我在使用“literal”修饰符声明成员类型“name”时遇到错误。
ref class CreditCardAccount
{
public:
static CreditCardAccount ();
CreditCardAccount (long number, double limit);
void SetCreditCardLimit (double amount);
bool MakePurchase (double amount);
void MakeRepayment (double amount);
void PrintStatement ();
long GetAccountNumber ();
static short GetNumOfAccounts ();
literal String name = "Super Platinum Card";
private:
initonly long accountNumber;
double currentBalance;
double creditLimit;
static short numOfAccounts;
static double interestRate;
};
Run Code Online (Sandbox Code Playgroud)
当我尝试引用类型“名称”时出现错误,例如:
Console::Write("Card name is ");
Console::WriteLine(CreditCardAccount::name);
Run Code Online (Sandbox Code Playgroud)
错误:
error C2146: syntax error : missing ';' before identifier 'String'
error C4430: missing type specifier …Run Code Online (Sandbox Code Playgroud) 我正在看HTHUMBAIL的窗户,寻找它的意思,但结果却找不到.我甚至在msdn上进行了范围搜索.我的问题在哪里可以找到HTHUMBNAIL的文档?