When I create a function, I can put the code for it after main if I put the prototype above main. For example,

int myFunction(int a)
{
return(a);
}

would have the prototype..

int myFunction(int a);

above main.

However, I have not been able to get this to work for a class definition.

If I put …

class myClass
{

};

below main,

I get an error if I put

class myClass;

above main. The error occurs where the class is used within main, and the error is "unknown type name." That's with the c++ compiler that is part of Xcode.

What kind of prototype should I enter above main if the class definition is below main?

When you call a function and the definition is not available, the compiler doesn't have to know the contents in order to continue evaluating the rest of the code (eg: stack usage at the call site). It only needs to know the function's signature to ensure
the correct parameters are going to be passed into the function. The linker will hook up the actual address for the function call after the compiler is done.

However when you are using a class it has to know about the details of it - not just that it exists - because it'll need to ensure proper layout on the stack, what parameters are required for the constructor, etc.

The details of the class' functions are of course like regular functions - it just needs the signature to work with - they can be defined later.

Placement of class definition and prototype的更多相关文章

  1. Java 8 的 Nashorn 脚本引擎教程

    本文为了解所有关于 Nashorn JavaScript 引擎易于理解的代码例子. Nashorn JavaScript 引擎是Java SE 8的一部分,它与其它像Google V8 (它是Goog ...

  2. Sublime相关

    通过添加 Build System 的方式来使 Sublime Text 3 运行 JS.ES6: 参考文章:如何优雅地使用Sublime Text3 参考书目:<ES6标准入门>阮一峰 ...

  3. JS创建类以及类的方法(StringBuffeer类)

    创建StringBuffer类以及toString,append()方法 //创建一个StringBuffer类 ,此类有两个方法:一个是append方法一个是toString方法 function ...

  4. 容器工厂(原型&单例)

    上一篇讲的是容器工厂的原型. 我们可以不必通过new关键之创建实例,可以直接取容器里面的实例. 我们可以发现,在对比他们的地址值的时候,他们是相同的为true. 如果我们需要的是不一样的呢.也就是有一 ...

  5. 让bootstrap-table支持高度百分比

    更改BootstrapTable.prototype.resetView 方法,以支持高度百分比定义,适应不同高度屏幕 BootstrapTable.prototype.resetView = fun ...

  6. es6/es7/es8常用新特性总结(超实用)

    本文标题有误导性,因为我其实想写node8的新特性,说实话一下子从node v1.x跳跃到node 8.x+ 真有点受宠若惊的感觉.一直觉得node 数组. 对象.序列等的处理没有python方便,因 ...

  7. bootstrap 固定表头

    1 htmL <!DOCTYPE html> <html> <head> <title>Fixed Columns</title> < ...

  8. beans有无状态

    Spring Bean Scopes https://www.tutorialspoint.com/spring/spring_bean_scopes.htm When defining a < ...

  9. siriWave.js的demo

    demo.html <style>body { background: #000; }</style> <script src="../siriwave.js& ...

随机推荐

  1. ScriptOJ-unique#89

    一般做法 const unique = (arr) => { const result = arr.reduce((acc, iter) => { if(acc.indexOf(iter) ...

  2. Django积木块二——邮箱

    邮箱 django中自带的功能,因为登录注册都需要邮箱,因此新增了一个小的app--utils用来存放 # email_send.py import random from django.core.m ...

  3. 卷积(转自wiki百科)

    维基百科,自由的百科全书 图示两个方形脉冲波的卷积.其中函数 "g" 首先对  反射,接着平移 "t" ,成为  .那么重叠部份的面积就相当于 "t& ...

  4. CMD指令及其意义

    1. appwiz.cpl:程序和功能 2. calc:启动计算器 5. chkdsk.exe:Chkdsk磁盘检查(管理员身份运行命令提示符) 6. cleanmgr: 打开磁盘清理工具 9. cm ...

  5. 菜刀(代码执行)函数和命令执行函数详解及Getshell方法

    i春秋作家:大家奥斯的哦 原文来自:https://bbs.ichunqiu.com/thread-41471-1-1.html 代码执行函数 VS 命令执行函数 一直想整理这两块的内容,但是一直没时 ...

  6. JavaScript实现页面显示倒计时功能

    下面是用JS中的日期函数和定时器完成的一个倒计时的例子,效果如图: 代码如下: <!DOCTYPE html> <html> <head> <title> ...

  7. MANIFEST.MF文件详解

    1. 依赖包是否在classpath中: 2. 资源文件目录是否在classpath中: 3. 主类是否正确: 具体配置参考 maven-jar-plugin 配置 <plugin> &l ...

  8. 使用MultipartFile上传文件

    转载地址:https://www.cnblogs.com/lunaticcoder/p/9813483.html(具体的看这个这个大佬的博客) 依赖包: <!-- 上传文件依赖组件 --> ...

  9. 机器学习技法笔记:09 Decision Tree

    Roadmap Decision Tree Hypothesis Decision Tree Algorithm Decision Tree Heuristics in C&RT Decisi ...

  10. 一个 react 小的 demo

    一.搭建开发环境: webpack构建工具. 新建一个文件夹(login),进入根目录, 1.输入命令:cnpm init,生成了一个package.json文件,这是一个标准的npm说明文件,里面蕴 ...