2015-02-07 2 views
0

구조체 형식이있는 벡터의 크기를 가져 오는 데 문제가 있습니다. apples.h :C++ 구조체 형식의 벡터 크기를 얻는 방법

#ifndef APPLES_H 
#define APPLES_H 
#include <vector> 
#include <iostream> 

struct a{ 
    int b; 
    bool c; 
}; 

class apples 
{ 
    public: 
     apples(); 
     ~apples(); 
    protected: 
    private: 


     static std::vector<a> d; 

}; 

#endif // APPLES_H 

apples.cpp : MAIN.CPP 나던 심지어 사과 클래스를 이렇게 부릅니다 :

#include "apples.h" 

std::vector<a> d; 

apples::apples() 
{ 
    std::cout<<d.size()<<std::endl; 
} 

apples::~apples() 
{ 
    //dtor 
} 

이 코드는 나에게 " 'D 사과'정의되지 않은 참조를"제공 나는 게시 지점을 보지 못합니다

+0

추가 설명 : http://stackoverflow.com/questions/7531981/how-to-instantiate-a-static-vector-of-object – TriHard8

답변

1

std::vector<a> d;d 앞에 클래스 이름이 없습니다. 이것은 당신의 오류를 수정해야합니다

std::vector<a> apples::d; 

그렇지 않으면 컴파일러가 그 applesd의 정의의 알 수 없다.