My first CXX problem:"aggregate has incomplete type and cannot be defined"

来源:互联网 发布:知彼网络 编辑:程序博客网 时间:2024/06/04 19:51
When I test to code in CPP, I meet a problem. And It's error:aggregate ‘Printer My_Printer’ has incomplete type and cannot be defined.
    After my debug I realized that there is an error in my statement in class. I statement my class in hello.cc file is fault, And when I move the statement into hello.h file the error is disappear.

hello.cc

点击(此处)折叠或打开

  1. /***************************
  2.  *filename:hello.cc

  3.  *filedescription:test

  4.  *writer:warrior

  5.  *date:2015/4/5

  6.  *mail:675979646@qq.com
  7.  **************************/

  8. //include
  9. #include "hello.h"


  10. using namespace std;
  11. //define


  12. //variable

  13. //class


  14. //function

  15. /*********************
  16.  *function name:void hello()

  17.  *function discription:

  18.  *parameter:
  19.     input: NULL
  20.     output: NULL
  21.  ********************/
  22. void Printer::Hello()
  23. {
  24.     char name[10];
  25.     cout<<"Please input your name :"<<endl;
  26.     cin>>name;
  27.     cout<<"Hello C++!"<<endl;
  28.     cout<<"I am "<<name<<" ."<<endl;
  29. };

hello.h

点击(此处)折叠或打开

  1. #ifndef _HELLO_H_
  2. #define _HELLO_H_
  3. //include
  4. #include <iostream>
  5. #include <sstream>

  6. class Printer
  7. {
  8.     private:
  9.         int Serial_Number;
  10.     public:
  11.         void Hello();
  12. };
  13. #endif

main.cc

点击(此处)折叠或打开

  1. /***************************
  2.  *filename:main.cc

  3.  *filedescription:test

  4.  *writer:warrior

  5.  *date:2015/4/5

  6.  *mail:675979646@qq.com
  7.  **************************/
  8. //include
  9. #include "main.h"

  10. using namespace std;
  11. //define


  12. //variable


  13. //function

  14. /*********************
  15.  *function name:int main()

  16.  *function discription:the main function

  17.  *parameter:
  18.     input: NULL
  19.     output: NULL
  20.  ********************/
  21. int main()
  22. {
  23.     Printer My_Printer;
  24.     My_Printer.Hello();
  25.     return 0;
  26. }

main.h

点击(此处)折叠或打开

  1. #ifndef _MAIN_H_
  2. #define _MAIN_H_

  3. #include <stdio.h>
  4. #include "hello.h"
  5. #endif

makefile

点击(此处)折叠或打开

  1. #makefile demo V1.0
  2. #author: warrior
  3. #mail:675979646@qq.com
  4. #date:2015/4/5

  5. CXX := g++
  6. CFLAGS := -c -g -W -Wall
  7. DIR := ./

  8. SOURCES := $(shell ls *.cc)
  9. OBJS := $(patsubst %.cc,%.o,$(SOURCES))
  10. TARGET := target


  11. ${TARGET} : ${OBJS}
  12.     ${CXX} -o $@ $^

  13. %.o : %.cc
  14.     $(CXX) ${CFLAGS} -o $@ $<




  15. .PHONY : clean
  16. clean :
  17.     -rm -f *.o target



<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(49) | 评论(0) | 转发(0) |
0

上一篇:My understand of KMP describe in C

下一篇:define function pointer

相关热门文章
  • test123
  • 编写安全代码——小心有符号数...
  • 使用openssl api进行加密解密...
  • 一段自己打印自己的c程序...
  • sql relay的c++接口
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
原创粉丝点击