Placement of class definition and prototype
来源:互联网 发布:java初级中级高级 编辑:程序博客网 时间:2024/06/06 01:20
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
- non-compatible bean definition of same name and class [x
- ....conflicts with existing, non-compatible bean definition of same name and class
- conflicts with existing, non-compatible bean definition of same name and class
- SpringMVC conflicts with existing, non-compatible bean definition of same name and class 的解决办法
- SpringMVC 启动报错,conflicts with existing, non-compatible bean definition of same name and class ...
- [工作点滴]SpringMVC conflicts with existing, non-compatible bean definition of same name and class
- conflicts with existing, non-compatible bean definition of same name and class
- SpringMVC conflicts with existing, non-compatible bean definition of same name and class 的解决办法
- 异常解决:non-compatible bean definition of same name and class【com.xxx.xxx.XXX】
- SpringMVC conflicts with existing, non-compatible bean definition of same name and class 的解决办法,sprin
- 记录:non-compatible bean definition of same name and class [com.XXX.XXX]
- CPP-类的位置(Placement of class)
- outside of class is not definition
- Definition of Mission, Goal, Objective and Strategies
- Definition and Function of a Shell
- class definition
- Ontology ---------- the definition of philosophy and in IT field
- C#: Problem trying to resolve a class when two namespaces are similar
- FaceBook机器学习开源DL模块
- shell编程基础
- 点积分换地方和基督教和发动机合肥几点回房间倒海翻江
- Android组件基本介绍之Activity
- Placement of class definition and prototype
- c语言sockt实现通过浏览器访问ip返回数据
- LeetCode 89 Gray Code
- Integer to Boolean strange syntax
- Partition List
- 【Android基础篇】使用<include>标签分割Layout
- 3_9988袖但闽暑德檬谗震直经
- 一亩田GIT基础教程
- 各种移动GPU压缩纹理的使用方法