C++ :: Template Compilation Differences Between MSVC And Clang

Nov 20, 2014

I've been writing a game engine in C++ for a little over a year now, and its been really fun so far. I've been focusing on windows support for now (using Visual Studio and MSVC) but I'd like to leave the possibility of Linux and Mac support open. As a test, I recently compiled a small portion of my reflection system in Clang, to make sure it all still worked (since I consider that the most advanced portion of my codebase, though I'm pretty sure its all standard C++11). Anyway, I got some strange errors regarding undefined identifiers in template functions, and I managed to isolate the issue in the code below:

#include <iostream>
#include <string>
using namespace std;
template <class UserType>
string DoSomething() {
return TypeInfo<UserType>();

[Code] ....

Clang throws an error about 'TypeInfo' being undefined when 'DoSomething()' is compiled. However, MSVC compiles the code above without so much as a warning.

This goes against my understanding of how template functions/classes were compiled. I always thought that Undefined symbols were not an issue in templates, as long as they were defined by the time the template was instantiated. Whats the issue here? If in fact MSVC has been doing some non-standard stuff, that's pretty unfortunate for me if I want Linux support, as I'll have to do some serious backflips to resolve all the issues with this in my headers and stuff (I can't be the only one in thinking the current state of C++ with headers and forward-decelerations is just awful to work with).

View 1 Replies


ADVERTISEMENT

C++ ::  How To Use G++ Or Clang In IDE

Apr 11, 2014

I am creating a simple IDE that has an editor + compiler. It has syntax highlighting, code completion, etc. It returns the C++ code (it's a C++ IDE) in a string, I need to compile that string of C++ code and if there are errors let the compiler (g++ or clang) send the errors back to my program, so I could format the error output. Is that possible without adding the compiler's whole code base to my IDE source code? Or can I use something like fork() or exec() to do something of that kind?

View 9 Replies View Related

C/C++ :: NNS Search Using Sum Of Squared Differences

Aug 7, 2014

I'm trying to get a project for an assignment. I have got it nearly working but the final result is completely erroneous. We are given two text files. One that has a noise image. This needs translating into a binary image. Which is quite easily. Using a threshold I just cycle through a loaded text file with a threshold and it refines the image perfectly. Then it saves fine. Obvious with this being a binary image it saves it as values of 1 and 0. However, the other text file is a shuffled image in set block sizes (512 x512 image into blocks of 32x32) with values of 0 or 255 for each cell.

So I set the cell values of 1 to 255 and 0 remain the same. Here is where I have the problem. My solution has to use a Nearest Neighbour search using Sum of Squared Differences. I have constructed a solution that should work on paper but it gives me a completely erroneous output for the solution to the second image.

My solution is to go by each block X and Y (512/32 = 16 x and 16 Y blocks) of the binary image(allmost perfect normal image) and for each one find the lowest SSD score and set the solution as it. Then goto the next block and repeat. Here is a copy of some of my code.

.H info

class Matrix {
int M, N;// No of rows and columns
public:
Matrix(int sizeR, int sizeC, double* input_data);
Matrix();// default constructor for empty type
Matrix(int asizeR, int sizeC);
double get(int i, int j)const;

[Code]....

It then writes to file. I excluded the binary image as I know that is all correct.

View 10 Replies View Related

C/C++ :: NNS Search Using Sum Of Squared Differences?

Aug 7, 2014

I'm trying to get a project for an assignment. I have got it nearly working but the final result is completely erroneous.

We are given two text files. One that has a noise image. This needs translating into a binary image. Which is quite easily. Using a threshold I just cycle through a loaded text file with a threshold and it refines the image perfectly. Then it saves fine. Obvious with this being a binary image it saves it as values of 1 and 0. However, the other text file is a shuffled image in set block sizes (512 x512 image into blocks of 32x32) with values of 0 or 255 for each cell.

So I set the cell values of 1 to 255 and 0 remain the same. Here is where I have the problem. My solution has to use a Nearest Neighbour search using Sum of Squared Differences. I have constructed a solution that should work on paper but it gives me a completely erroneous output for the solution to the second image.

My solution is to go by each block X and Y (512/32 = 16 x and 16 Y blocks) of the binary image(allmost perfect normal image) and for each one find the lowest SSD score and set the solution as it. Then goto the next block and repeat. Here is a copy of some of my code.

.H info

class Matrix {
int M, N;// No of rows and columns
public:
Matrix(int sizeR, int sizeC, double* input_data);
Matrix();// default constructor for empty type
Matrix(int asizeR, int sizeC);
double get(int i, int j)const;
~Matrix();

[code].....

View 1 Replies View Related

Visual C++ :: Profiling Tool For MSVC?

Mar 15, 2013

Is there a profiling tool for MSVC that is free to use?

View 4 Replies View Related

Visual C++ :: How To Make Icon For MSVC Project

Oct 22, 2013

I'm developing a software for Windows using MSVC 2010. My employer sent me 2 png files: 16x16 and 32x32 for the icons.

What I would like to do is to use them as a MSVC icon resource and don't use any code hacks. In the past all I had was an ico file and I just included it in the resource (rc) file for Visual Studio and that was it.

Now my question is: how do I make one ico file out of those 2 png files that will be accepted by MSVC? Is there a tool (preferably free) for it or some online service?

View 3 Replies View Related

C++ :: Compiler / Linker Differences In Visual Studio Conversion?

Mar 18, 2014

I have a project that is essentially a hot pot of C/asm (naked functions etc). The code gets injected into another EXE. It works fine when compiled in Visual C++ 6 but when compiled in Visual Studio 2008 it compiles fine but falls over in use.

Are there certain settings I need to look out for? I have optimization disabled and as far as I can tell the command line options for compiler/linker are the same (given the differences).

I have opened both builds in IDA and the 2008 build has more import and offset jumps are in different places.

View 1 Replies View Related

C/C++ :: Node Insertion Into Boost Libraries - PTree Not Working In MSVC

Dec 24, 2014

I'm currently working on a Microsoft (unmanaged) C++ project which utilizes Boost C++ libraries. It's been quite a while since I've done C++ and I have no previous experience using the Boost libraries.

We are using Boost 1.55 and MSVC 2013. We used CMake to generate the Visual Studio solutions and projects based on the original project layout.

We've successfully built and tested on other environments. In the MSVC - Windows environment, we've run into issues using Boost's Property Tree support. Specifically, the issue seem to center around trying to put properties into PTNodes.

Consider the following code snippet:

void XXX:: SomeFunction() {
PTnode ptNode;
ptNode(Mapper::KEY_INPUT, Tracer::SOME_VALUE);
ptNode(Mapper::KEY_OUTPUT)(Tracer::SOME_OTHER_VALUE, Tracer::ADDITIONAL_VALUE);
SetResults(ptNode);

[Code] ....

This work around seems insert the nodes successfully into the tree.

We are able to verify by finding the inserted items in ::SetResult().

Why this might be failing in VisualStudio C++?

Is this an issue of compiler flags?

precompiler definitions?

Linker options??

Memory mode/model??

Are there some basic behaviour differences in MSVC C++ and other C++ environments which we are unaware of?

I've tried to identify all instances of the node insert pattern and use the work around. But, we really need to find out what the issue is (as there could be other manifestations).

View 1 Replies View Related

C :: How To Retain Dos Windows After Compilation Is Done

Apr 2, 2013

i am just making some new programmings and testing it. But every time after compile and run The dos window is closing and again I have to compile And run command so i want The dos windows should prompt me for next input rather than closing.

View 2 Replies View Related

C++ :: Allegro5 Library Compilation

Feb 5, 2015

I have a problem with compiling the Allegro5 library:

"Cannot find allegro-5.0.10- monolith.mt"

source:

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <cmath>
int main() {
al_init();
al_init_primitives_addon();
al_install_keyboard();
ALLEGRO_KEYBOARD_STATE klawiatura;

[Code] ....

View 1 Replies View Related

C++ :: Compilation In Machine Language

Jan 25, 2013

Have a program which given a C source code file, gives back RAW MACHINE CODE, which means it doesn't have to be a executable on his own.

Like:

Given a example function for C:

int stdcall Function(void)
{
return 0;
}

Gives back the Machine Code for the Example Function.

It doesn't need to be actual C code, it can also be like:

type int
return 0

Or also it can be a straight assembly-to-machine-code compiler.

Is there any Library? Or even a external tool I can look into?

View 4 Replies View Related

C++ :: Objects / Classes And Separate Compilation

Apr 9, 2013

Code:
class A
{
public:A(int a, int b);
};

I need to have an object of class A that doesn't have a default constructor in another class, B:

Code:
class A; //This is in a separate header file
class B
{
private:A a;};

The problem is that it won't compile without a default constructor. I'm not allowed to define a default constructor, and the A object in class B has to be private so I can't initialize A a in public.

I also can't change the prototype in the interface to something like

A(int a = 0, int b = 0);

since one of the requirements is that if an object of class A is declared in main, it must not compile due to not having a default constructor. So what can I do to make class B work and compile?

Another question I have is why is this valid:

Code:
class A; //#include "A.h" is in the implementation file so it compiles.
class B
{
private:A* a;}; But not this: Code: class A;

class B
{
private:A a;};

This is for a project that I probably won't be able to turn in on time, but I care more about how to do this right than turning it in for full points.

View 4 Replies View Related

C++ :: Compilation Error Redefining Object

Oct 17, 2013

main:

#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Board.cpp"
int main(int argc, char* argv[]){
argc=5;
argv[argc];

[Code] .....

I can't find a place where there are two definitions of any of the Board methods

View 9 Replies View Related

C++ :: Activate Cat Method Makes Compilation Error

Jul 5, 2014

Considering this small code:

Here a template array class is written and also a cat class. The cat class has "present" method.

the array is initialized with 20 cats. yet, trying to activate a cat methods makes a compilation error:

Code:
#include <iostream>
using namespace std;
template <class T>
class Array{
private:

[Code].....

how do we make it work? I'm sure there's a way I'm not aware of since if we can't - what is the point of templates?

View 6 Replies View Related

C++ :: Logging In Multiple Files - Compilation Errors

Sep 25, 2014

I am working on one application that requires extensive logging so I want to create a log file of each day during execution.

I tried easylogging++ but i am unable to use into multiple files. If i try to use in other file. I get compilation errors of using same functions or methods already defined.

How can i use macro to hide the implementation of logging in one class to other ??

View 1 Replies View Related

Visual C++ :: Conditional Compilation Based On Whether It Is Windows 7 Or 8?

Apr 10, 2013

I want to do conditional compilation based on whether it is windows 7 or windows 8. Here is the code below.

#if (_WIN32_WINNT >= 0x0602) //Condition to check whether it windows 7 or 8 .Based on this we can load msxml 3 or 6.
#import <msxml6.dll>
#else
#import <msxml3.dll>
#endif

Im building the above code in windows 8 machine.

Issue here is _WIN32_WINNT should have a value 0x0602, it means it is running in windows 8 machine.Instead it has a value 0x0601 (Means it is taking windows version as windows 7 defined in sdkddkver.h).Im not sure after installing windows 8 sdk im not able to see any include or lib files in the path below C:Program Files (x86)Microsoft SDKsWindowsv8.0A . but i can see all include and lib files of sdk version v7.0A available although i did not installed it.

View 5 Replies View Related

C++ :: Passing Array Of Object Gives Compilation ERROR

Dec 21, 2012

This is my question : Define a class named HOUSING in C++ with the following descriptions:

Private members
REG_NO integer(Ranges 10 - 1000)
NAME Array of characters(String)
TYPE Character
COST Float

Public Members
-Function Read_Data( ) to read an object of HOUSING type
-Function Display() to display the details of an object
-Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.

Now I' trying to do this by this way

Code:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class housing {
private:
int REG_NO;
char NAME[10];

[Code] .....

I am trying to pass the entire array of object in DrawNos(). but getting compilation error -

32: 'housing:rawNos(housing * *)' is not a member of 'housing'
48: Structure required on left side of . or .*

What is the problem? How can I pass the array of object in function and use it.

View 3 Replies View Related

C++ :: Compiler Not Having A Proper Order Of Compilation For Header Files

Jun 1, 2014

Today I experienced a very strange compiler issue. I started the compilation and it outputted that a member object of a class was undefined. After about 4 hours of trying the find the bug I commented and then uncommented said line of code that was undefined. Sure enough the compilation worked just from commenting and uncommenting.

I am using Microsoft visual studio 2012 express. Due to the size of the project, I should know the cause because it may cause more problems further down the line. I feel that it might have something to do with the compiler not having a proper order of compilation for the header files and that I might need something to solidify the way that the header files are processed. The below code is a fragment of a header file.

class CInGameSection: public CBaseGameSection {
public:
CInGameSection(bool isInEditor, bool creatingNew, COutput& output, string saveSlot, string regionName, horiVertiVals * widthAndHeight);
~CInGameSection();
bool update(CInput & input, CAudio & audio, COutput & output);
void output(CInput & input, CAudio & audio, COutput & output);

[code]...

View 3 Replies View Related

C++ :: Parsing A Text File - Detect When Certain Compilation Condition Begins

Dec 8, 2014

I'm parsing a text file, and I'd like to detect when a certain Compilation Condition - i.e. #ifdef - begins. The challenge is, that the condition can take any of the following patterns:

#ifdef (FLAG)
#if defined (FLAG)
#if (defined (FLAG))

(And perhaps I missed more)

I'd of course need to treat them all the same, as they are indeed the same. How would you know to treat them all the same?

View 2 Replies View Related

C++ :: Generic Linked List Compilation Errors / Incompatible Pointer Type

May 19, 2014

I am trying to write a generic linked list in c, but for some reason i keep getting errors saying "incompatible pointer type. This is the code and erros:

#ifndef SLIST_H
#define SLIST_H
#include <stdlib.h>
typedef struct {
void *data;
slist_elem *next;

[code]....

View 2 Replies View Related

C :: Count Lines In Input And Display Output In Terminal When Program Executed After Compilation

Feb 4, 2013

Code:

#include <stdio.h>
main() {
int c, n1;
n1 = 0;
while ((c = getchar()) != EOF)
if (c == '')
++n1;
printf("%d", n1);
}

I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. count the lines in input and display the output in terminal when ./program is executed after compilation. To count and compute lines, words and within arrays.

View 4 Replies View Related

C++ ::  how To Declare Template Function Inside Template Class

Dec 5, 2013

I'm trying to implement a simple template array class, but when i came into the operator< i actually have to use a template :

my code is something like :

template<typename _Type, std::size_t _Size>
class array {
public :

[Code] ......

but i am having an error of shadows template param 'class _Type' is it w/ the name conflict between the array template parameter and the function template parameter ?

View 6 Replies View Related

C++ :: Use Of Class Template Requires Template Argument List

Nov 6, 2013

Error1error C2955: 'DoubleLinkedListInterface' : use of class template requires template argument listdoublelinkedlist.h10
Error2error C2244: 'DoubleLinkedList<T>::DoubleLinkedList' : unable to match function definition to an existing declaration doublelinkedlist.cpp7

Error3 .cpperror C2244: 'DoubleLinkedList<T>::~DoubleLinkedList' : unable to match function definition to an existing declaration 12

.h

#pragma once
#include "DoubleLinkedListInterface.h"
#include "Node.h"
#include <iostream>

[Code]....

View 4 Replies View Related

C++ :: Partial Template Specialization With Template Class

May 27, 2013

I have a generic template class with another template in one of its types. Now I want to specialize one of its methods for a particular (template) class, which leads to a compile error, however.

Here is the example:

#include <stdio.h>
template<typename Type>
class Obj1 {
public:
void ID() { printf("Object 1, size = %zu

[Code] .....

GCC ends with:
:35:27: error: type/value mismatch at argument 2 in template parameter list for ‘template<class Type, template<class> class O> class Foo’
:35:27: error: expected a class template, got ‘Obj2<Type>’

What is wrong with the specialization? Can it even be achieved and how (if so)?

View 1 Replies View Related

C++ :: Template With A Specialized Template Class Parameter?

Nov 2, 2014

how I want the code to look. Only problem is it doesn't work (Line 11). I have some experience with templates but I'm not a pro.

Basically I want the "Channels<3>" to be a type that I can use to specify a Cable with similar to vector<float/int> it would be Cable<Channels<2 or 3>>.

What have I messed up with the syntax?

#include <iostream>
#include <vector>
using namespace std;

[Code].....

View 4 Replies View Related

C++ ::  Writing A Function Template With Template Arguments?

Mar 14, 2014

I have a function:

template<class Iterator, class T>
void a(Iterator, Iterator, const T&);

and I want to be able to simplify calls to 'a' with calls like

a(someIteratableContainer);

instead of having to call:

a(someIteratableContainer.begin(), someIteratableContainer.end(), valueOfTheContainersElementType);

I also want to be able to generalize the function to handle any of the standard iteratable contains: array, vector, deque, whatever.

I was under the impression I could write:

template<template<class T> class U> a(U<T>& container) {
a(container.begin(), container.end(), g(T()));
}

where 'g()' returns an object of the element type. However, the compiler is claiming, no matter how I write a call to the overload, the original template is selected and/or the overload is invalid, depending on the various ways I attempt to write said overload.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved