小编noo*_*lla的帖子

Objective-C - 私人与受保护对公众

我希望在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)

objective-c

37
推荐指数
2
解决办法
4万
查看次数

C++ - 如何重置输出流操纵器标志

我有一行代码在我的输出中将填充值设置为' - '字符,但需要将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)

我走错了路吗?

c++ manipulators

17
推荐指数
3
解决办法
2万
查看次数

基本C++递归程序问题

//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)

c++ recursion

1
推荐指数
1
解决办法
1576
查看次数

需要帮助解决三个visual studio错误 - 在尝试构建解决方案时出现C++错误

我尝试构建此项目时出现以下错误:

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)

c++ visual-studio

1
推荐指数
1
解决办法
193
查看次数

无法检测到导致语法错误的行

你好!我正在从我的一个编程课程开始一个旧项目,并且有一些问题需要跟踪我的代码中的哪一行导致语法错误.

当我尝试编译代码时,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)

c++ syntax

0
推荐指数
1
解决办法
186
查看次数

一个简单的If ... else块.为什么什么都不做?

 <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)

javascript

0
推荐指数
1
解决办法
251
查看次数