Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Ругаеться на NULL и на параметры по умолчинаю.


Автор: Elfet 19.11.2006, 16:13
Отдельно всё работает. А если это этот же код подключаю к проекту на C# то вот какие ошибки:
Цитата

Error    1    error C3222: 'x' : cannot declare default arguments for member functions of a managed type or generic functions    c:\documents and settings\melethron\мои документы\visual studio 2005\projects\graph\graph\Graph.h    34    
Error    2    error C3222: 'y' : cannot declare default arguments for member functions of a managed type or generic functions    c:\documents and settings\melethron\мои документы\visual studio 2005\projects\graph\graph\Graph.h    34    
Error    3    error C2065: 'NULL' : undeclared identifier    c:\Documents and Settings\Melethron\Мои документы\Visual Studio 2005\Projects\Graph\Graph\Graph.cpp    12    




Код

// This is the main DLL file.

#include "stdafx.h"

#include "Graph.h"

using namespace GraphSpace;

Graph::Graph()
{
    graph = new Peak;
    graph->next = NULL;
    graph->numer = 0;
    graph->x = 0;
    graph->y = 0;
    graph->ribs = NULL;
    EnableLoops = false;
    EnableRepeat = false;
}




Код

// Graph.h

#pragma once

using namespace System;

namespace GraphSpace {
    struct Rib;
    struct Peak
    {
        int numer;
        int x;
        int y;
        Peak * next;
        Rib * ribs;
    };
    struct Rib
    {
        Peak * toPeak;
        Rib * next;
    };
    public ref class Graph
    {
    private:
        Peak * graph;
    public:
        bool EnableLoops;
        bool EnableRepeat;
    public:
        Graph();
        //Graph(const Graph & copy);
        ~Graph();
        void print();
        bool AddPeak(int x = 0, int y = 0);
        bool DeletePeak(int the);
        bool RenumerPeak(int the, int to);
        bool MovePeak(int the, int x, int y);
        bool AddRib(int from, int to);
        bool AddDoubleRib(int the1, int the2);
        bool DeleteRib(int from, int to);
        bool DeleteDoubleRib(int the1, int the2);
    private:
        Peak * GetPeak(int the);
        Peak * EnablePeak();
        int EnableNumer();
    };
}

В чём проблема может быть?

Автор: Rockie 19.11.2006, 17:19
Elfet, возможно MSDN поможет: http://msdn2.microsoft.com/en-us/library/zk03y5fe.aspx

Видать ему не нравятся аргументы по умолчанию здесь: 
Код
 bool AddPeak(int x = 0, int y = 0);

Цитата
It is not permitted to declare a method parameter with a default argument. An overloaded form of the method is one way to work around this issue. That is, define a method with the same name with no parameters and then initialize the variable in the method body.

Автор: Любитель 20.11.2006, 14:56
Итак, для менежед-кода создавай три функции:
Код

bool AddPeak(); // x = 0, y = 0
bool AddPeak(int x); // y = 0
bool AddPeak(int x, int y);

CLR (C# в частности) не поддерживают дефолт-аргументов. Хотя MS могли бы сделать компилер для C++/CLI, позволяющий автоматом генерить несколько перегруженных функций...

Автор: Elfet 20.11.2006, 18:07
Ну ваще! smile Ну дают! smile

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)