我希望在Objective-C中编程时,私有vs保护与公共关于类成员如何工作的一些澄清 - 我以为我知道区别(我已经向我的父类Person添加了一些评论)但是当我试图通过子类访问父类的私有ivar /成员时,编译器没有抱怨的事实让我感到困惑.
这是我的父类:
/*
Person.h
*/
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
//We can also define class members/iVars that are of type private
//This means they can only be accessed by the member functions
//of the class defining them and not subclasses
@private
int yob;
//We can also define class members/iVars that are of type public
//Public members can be accessed directly
@public
bool alive;
//By default class members/iVars are of type protected
//This means they can …Run Code Online (Sandbox Code Playgroud) 我有一行代码在我的输出中将填充值设置为' - '字符,但需要将setfill标志重置为其默认的空白字符.我怎么做?
cout << setw(14) << " CHARGE/ROOM" << endl;
cout << setfill('-') << setw(11) << '-' << " " << setw(15) << '-' << " " << setw(11) << '-' << endl;
Run Code Online (Sandbox Code Playgroud)
我认为这可行:
cout.unsetf(ios::manipulatorname) // Howerver I dont see a manipulator called setfill
Run Code Online (Sandbox Code Playgroud)
我走错了路吗?
//This program finds the GCD of two numbers using a recursive function call via the
//Euclidean algorithm
#include <iostream>
#include <cmath>
using namespace std;
int GCD (int A, int B);
int main()
{
int A = 45, B = 55;
cout << "The GCD is " << GCD(A,B) << endl;
//test
return 0;
}
int GCD (int A, int B)
{
A = abs(A);
B = abs(B);
if (A > B)
{
A = A - B;
return GCD (A, …Run Code Online (Sandbox Code Playgroud) 我尝试构建此项目时出现以下错误:
error C2182: 'read_data':illegal use of type 'void'
error C2078: too many initializers
errors c2440: 'initializing': cannot convert from 'std::ofstream' to int
Run Code Online (Sandbox Code Playgroud)
所有上述内容似乎都指向我在第72行的函数调用,这就是这一行:void read_data(finput,foutput);
我在MSDN网站上查找了这些错误代码,但无法使用描述来推断可能出错的地方.
任何想法/提示表示赞赏.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void read_data(ifstream& finput, ofstream& foutput);
//PRE: The address of the ifstream & ofstream objects is passed to the function
//POST: The data values are read in until the end of the file is reached
void print_data(ofstream& foutput, string fname, string lname, int largest, …Run Code Online (Sandbox Code Playgroud) 你好!我正在从我的一个编程课程开始一个旧项目,并且有一些问题需要跟踪我的代码中的哪一行导致语法错误.
当我尝试编译代码时,Visual Studio告诉我在包含此函数调用的行的main末尾有一个语法错误:
sortData(carray,numRec,sortby);
我不认为是这种情况,因为注释掉该调用只会将错误移动到下一行代码.
我不知道是什么导致了这个错误,我希望老手的眼睛可以提供帮助.
我已经包含了所有代码,因为我怀疑在其中一个函数调用中导致了错误.
ohbijuan
PS此外 - 有没有人知道编译器是从上到下编译还是在编译过程中它是否实际跟随函数调用?
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
//customer struct
struct customer
{
int id;
string fname, lname;
double totalQuantity, totalPurchases, totalProfit;
};
//Error Codes
const int INPUT_FILE_FAIL_NO_CONTINUE = 2;
const int INPUT_FILE_DATA_ERROR = 3;
//Global Constants
const int arraySize = 200;
const int numType = 5; //# of the types of coffee we currently offer
//Coffee prices per pound
const double colombWhole = 3.75;
const …Run Code Online (Sandbox Code Playgroud) <html>
<head></head>
<body>
<script type = "text/javascript">
var x = 5;
var y = 8;
if (x < 6)
{
document.write("They are equal");
}
else
{
document.write{"They are NOT equal");
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)