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. 【repost】JavaScript 基本语法

    JavaScript 基本语法,JavaScript 引用类型, JavaScript 面向对象程序设计.函数表达式和异步编程 三篇笔记是对<JavaScript 高级程序设计>和 < ...

  2. 关于调试WCF时引发的异常XmlException: Name cannot begin with the '<' character, hexadecimal value 0x3C” on Client Side

    问题描述:在使用VS2015调试WCF时,偶遇抛出异常名称不能以“<”字符(十六进制0x3c)开头,平时运行时(不调试)没有问题的. 解决方法:检查后发现为了检查异常的位置,勾选了引发通用语言运 ...

  3. Trinity的分步运行

    当使用Trinity组装时,如果数据量过大,可以考虑使用--min_kmer_cov 2参数丢弃uniquely occurring kmer, 从而降低内存消耗 设置--no_distributed ...

  4. 788. Rotated Digits

    X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...

  5. css插入背景图片底部有白边的解决方法

    相信很多小伙伴遇到过用CSS插入背景图时,底部出现白边的情况,如下图:   个人总结了2个方法如下: 解决方法1:给图片都加上 vertical-align: middle属性.有时,移动端也会有类似 ...

  6. 写一个shell 快速启动停止你的微服务吧

    在这个微服务盛行的时代,docker获得了巨大的成功,因为我们需要在一台服务器装上N个服务. 本文不是想讨论如何使用docker,而是,在一台服务器安装了多个服务后,怎样启动方便的启动服务呢? 一.在 ...

  7. itext实现合同尾部签章部分自动添加,定位签名

    使用的pom <!-- pdf处理 start--> <dependency> <groupId>com.itextpdf</groupId> < ...

  8. Java 命令行启动时指定配置文件目录

    java -jar -Xbootclasspath/a:/home/tms/conf    /home/tms/bin/S17-tms.jar 先指定配置文件目录: 再指定jar包路径: 运行clas ...

  9. Testing - 软件测试知识梳理 - 测试用例

    测试用例 是指对一项特定的软件产品进行测试任务的描述,体现测试方案.方法.技术和策略. 内容包括测试目标.测试环境.输入数据.测试步骤.预期结果.测试脚本等,并形成文档. 每个具体测试用例都将包括下列 ...

  10. php省市联动实现

    设计模式:ajax实现,数据库格式:id,name,parent_id 数据库: CREATE TABLE IF NOT EXISTS `city` ( `id` ) NOT NULL AUTO_IN ...