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. 使用Docker搭建CentOS 7 + Apache 2.4+ PHP7

    从Docker Hub上Pull最新的CentOS 7镜像并新建容器 # sudo docker pull centos docker run -p 8082:80 --name centos_c - ...

  2. ASP.NET MVC下使用AngularJs语言(八):显示html

    在Angularjs显示html文本,如果按照一般处理它.它只能页中显示没经解释文本. 在ASP.NET MVC添加一个控制器: 创建angularjs控制器: pilotApp.controller ...

  3. Android开发 - 掌握ConstraintLayout(四)创建基本约束

    上一篇我们介绍了编辑器的基本使用,本文我们介绍创建基本的约束. "约束"表示View之间的位置关系.当我们在ConstraintLayout布局中创建View时,如果我们没有添加任 ...

  4. HDU1542 扫描线(矩形面积并)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. 美团2018年CodeM大赛-初赛B轮 C题低位值

    试题链接:https://www.nowcoder.com/acm/contest/151/C 定义lowbit(x) =x&(-x),即2^(p-1) (其中p为x的二进制表示中,从右向左数 ...

  6. JavaScript的BOM编程,事件-第4章

    目标 BOM编程 window和document对象 window对象的属性和方法 document对象的属性和方法 JavaScript中对象的分类 浏览器对象:window对象 window对象, ...

  7. hystrix降级初步学习

    通过hystrix可以进行服务的限流.熔断.降级 配置 服务端Eureka server: port: 8761 # 指定该Eureka实例的端口 eureka: client: registerWi ...

  8. ASP.NET MVC 异常Exception拦截

    一.前言 由于客户端的环境不一致,有可能会造成我们预计不到的异常错误,所以在项目中,友好的异常信息提示,是非常重要的.在asp.net mvc中实现异常属性拦截也非常简单,只需要继承另一个类(Syst ...

  9. 机器学习技法笔记:01 Linear Support Vector Machine

    Roadmap Course Introduction Large-Margin Separating Hyperplane Standard Large-Margin Problem Support ...

  10. 获取CPU ID--查看CPU数量/核数

    Ubuntu 获取CPU序列号或者主板序列号 CPU ID 代码: sudo dmidecode -t 4 | grep ID ID: 54 06 05 00 FF FB 8B 0F 主板序列号 代码 ...