Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi,

I have an inline class (header file only), and I have the stdafx.h from VS

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>



// TODO: reference additional headers your program requires here
#include "TemplateContainer.h"
#include <vector>


Then I have my class....

C++
#pragma once

#include "stdafx.h"

template < class T >
class TemplateContainer
{
private:
	std::vector<T> myItems;
public:
	TemplateContainer()
	{

	}
	~TemplateContainer()
	{

	}

	void add(T &item)
	{
		myItems.push_back(item);
	}
};


This doesnt compile. I thought if I included vector in the stdafx then when my class includes stdafx it would indirectly pull in vector.h. However I have to explicitly
C++
#include <vector> 
to get my class to compile. Is there anything else I should be doing to use this VS feature ?

What I have tried:

I have tried including the file explicitly and it works, but the atdafx docs state i only need to include it in the stdafx.h file.
Posted
Updated 11-May-16 15:58pm

1 solution

Look at the order of the includes. Vector has to before your class header.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900