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

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) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值